git鏈接遠程倉庫

一開始按照廖雪峯官方網站的教程,學習本地git使用時還好,但是鏈接到遠程倉庫這裏就出現了各種錯誤,差點又從入門到放棄,學習git又搞了一下午加一晚上,總覺得自己效率太低。。這其實也沒有很難啊

報錯

1 $ git push origin master
[email protected]: Permission denied (publickey).
fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.
原因分析:這個問題可能就是因爲我沒有配置ssh,參考簡書這篇博客,步驟很詳細。還要說一點百度搜索解決辦法,搜索到的結果都是2016年之前的博客,都是配置ssh什麼的可能確實能解決但是我不懂,不是我想要的答案(我還是對百度去廣告搜索太過自信了。。。)。不得不說,Google大法真的好。
還有個github官方對這個報錯的解釋,也重點說了ssh的問題,不過沒有完全看懂。

2 $ git push
fatal: The current branch master has no upstream branch.
To push the current branch and set the remote as upstream, use git push --set-upstream origin master
3 $  git push --set-upstream origin master
Warning: Permanently added the RSA host key for IP address '52.74.223.119' to the list of known hosts.
To github.com:heatMa/learngit.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to '[email protected]:heatMa/learngit.git'
hint: Updates were rejected because the tip of your current branch is behind its remote counterpart. Integrate the remote changes (e.g.'git pull ...') before pushing again.See the 'Note about fast-forwards' in 'git push --help' for details.
原因分析:2和3的問題,原因可能是因爲我的test倉庫是以前學習時就有的(從入門到放棄再到入門),並不是新建的一個,新建了一個後發現就可以了。。。心中一萬頭草泥馬

並且新建倉庫的時候不要勾選用README初始化倉庫,因爲如果勾選了的話就不是空倉庫了,會出現本地和遠程倉庫不一致?我也不知道爲啥,就是會出錯;如果不勾選就不會出錯。

(不要勾選!!!)


分割線之我想說的是,貌似不用配置什麼

其實在github上新建一個空倉庫(不勾選用README初始化),彈出主頁上就給你說明白了怎麼用git和連接遠程倉庫。當然估計還是要配置密匙的,只不過我已經配好了,沒有環境驗證了。。改天用自己的破筆記本試一下。

當然,正如廖雪峯老師所提到的,這種方法纔是最好用的。先創建遠程庫,再從遠程庫克隆!!!這樣就沒有了讓我們關聯的問題。總的來說就是兩種思路:
一種是先建立本地倉庫,然後和github遠程倉庫同步;
一種是先在github上建立遠程倉庫,然後克隆到本地。


更新:

附一張在全新ubuntu系統裏,通過在遠程端克隆到本地,修改後再上傳修改到遠程倉庫的過程,感覺還是比較清晰的。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章