yinian 发表于 2018-1-15 08:33:53

Git ~ 添加远程仓库 ~Git

  现在的情景是 , 你已经在本地创建了一个Git仓库后 , 又想在 Github 创建一个Git 仓库并且让这两个仓库进行远程同步 , 这样Github 上的仓库既可以作为备份 ,有可以让其他人通过仓库来写作 , 真是一举多得。
  首先登陆Github在右上角点击"+"下拉目录进入 New repository然后输入一个名字 , 其余的 defult 然后直接 Create repository 创建完毕 。
  此时这个 learngit 仓库还是空的 , Github告诉我们可以从这个仓库克隆出来新的仓库 ,也可以把一个本地仓库与之关联 , 然后将本地仓库的内容 推送到 Github仓库 。
  现在 , 我们根据Github的提示 , 在本地的learngit仓库下运行命令
  

git remote add origin git@github.com:自己的名字/learngit.git  

  千万注意,把上面的自己的名字 改成自己的Github 账户名 , 否则 , 你在本地关联的就是我的远程库 , 关联没有问题 , 但是你以后推送不上去 , 因为你的SSH key公钥不在我的账户列表中 。 添加后远程库的名字就是 origin 这就是 Git的默认叫法 , 也可以改成别的 。
  下一步讲本地库的所有内容推送到远程库上:
  

xpower@xpower-CW65S:~/learngit$ git push -u xpower master  
The authenticity of host
'github.com (192.30.253.113)' can't be established.  
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
  
Are you sure you want to continue connecting (yes/no)? YES
  
Warning: Permanently added 'github.com,192.30.253.113' (RSA) to the list of known hosts.
  
对象计数中: 8, 完成.
  
Delta compression using up to 8 threads.
  
压缩对象中: 100% (5/5), 完成.
  
写入对象中: 100% (8/8), 730 bytes | 0 bytes/s, 完成.
  
Total 8 (delta 1), reused 0 (delta 0)
  
remote: Resolving deltas: 100% (1/1), done.
  
To git@github.com:A-FM/learngit.git
  
*       master -> master
  
分支 master 设置为跟踪来自 xpower 的远程分支 master。
  

  

git push xpower master  


SSH警告
  当你第一次使用Git的clone或者push命令连接GitHub时,会得到一个警告:
  

The authenticity of host 'github.com (xx.xx.xx.xx)' can't be established.  
RSA key fingerprint is xx.xx.xx.xx.xx.
  
Are you sure you want to continue connecting (yes/no)?
  

  这是因为Git使用SSH连接,而SSH连接在第一次验证GitHub服务器的Key时,需要你确认GitHub的Key的指纹信息是否真的来自GitHub的服务器,输入yes回车即可。
  Git会输出一个警告,告诉你已经把GitHub的Key添加到本机的一个信任列表里了:
  

Warning: Permanently added 'github.com' (RSA) to the list of known hosts.  

  这个警告只会出现一次,后面的操作就不会有任何警告了。
  如果你实在担心有人冒充GitHub服务器,输入yes前可以对照GitHub的RSA Key的指纹信息是否与SSH连接给出的一致。

小结

要关联一个远程库 , 使用命令
  

git remote add origin git@github.com:自己的名字/learngit.git  

  关联后,使用命令   进行第一次推送 。
  

git push -u xpower master  

  此后每次本地提交之后,制药友必要的话就可以使用 命令 git push xpower master 推送最新修改 。
页: [1]
查看完整版本: Git ~ 添加远程仓库 ~Git