远程仓库


创建远程仓库

GitHub 上创建远程仓库;


关联远程仓库

要关联一个远程库,使用命令 git remote add origin 远程库地址;

比如: $ git remote add origin https://github.com/Allbett/LearnGit.git 一般关联自己新建的库, GitHub 上面给出命令;

MaiBenBen@An MINGW64 /e/learnGit (master)
$ git remote add origin https://github.com/Allbett/LearnGit.git

将本地仓库推送到远程库

第一次 推送 master 分支的所有内容: git push -u origin master ,多加一个参数 -u

以后使用命令 git push origin master 推送最新修改;

MaiBenBen@An MINGW64 /e/learnGit (master)
$ git push -u origin master
fatal: HttpRequestException encountered.
   ▒▒▒▒▒▒▒▒ʱ▒▒▒▒
Username for 'https://github.com': 1255621959@qq.com
Counting objects: 12, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (7/7), done.
Writing objects: 100% (12/12), 1.10 KiB | 565.00 KiB/s, done.
Total 12 (delta 2), reused 5 (delta 1)
remote: Resolving deltas: 100% (2/2), done.
remote:
remote: Create a pull request for 'master' on GitHub by visiting:
remote:      https://github.com/Allbett/LearnGit/pull/new/master
remote:
To https://github.com/Allbett/LearnGit.git
 * [new branch]      master -> master
Branch master set up to track remote branch master from origin.


克隆远程仓库到本地

要克隆一个远程库,使用命令 git clone 远程库地址;

MaiBenBen@An MINGW64 /e/learnGit (master)
$ git clone git@github.com:Allbett/CopyLearnGit.git
Cloning into 'CopyLearnGit'...
The authenticity of host 'github.com (13.229.188.xx)' can't be established.
RSA key fingerprint is SHA256:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.
Are you sure you want to continue connecting (yes/no)? y
Please type 'yes' or 'no': yes
Warning: Permanently added 'github.com,13.229.188.xx' (RSA) to the list of known hosts.
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (3/3), done.


仓库地址协议

GitHub给出的地址不止一个,还可以用 https://github.com/GitHub-Name/Repository-Name.git 这样的地址。实际上, Git 支持多种协议,默认的 git:// 使用ssh,但也可以使用 https 等其他协议。

使用 https 除了速度慢以外,还有个最大的麻烦是每次推送都必须 输入口令但是在某些只开放http端口的公司内部就无法使用ssh协议而只能用https。

posted @ 2018-11-14 17:46  Yiaz  阅读(124)  评论(0编辑  收藏  举报