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
 * [new branch]      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 推送最新修改 。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM