一、背景
在git 提交的時候,突然就行不通,一直報錯:
-
Permission denied (publickey).
-
fatal: Could not read from remote repository.
-
-
Please make sure you have the correct access rights
-
and the repository exists.
二、解決方案
1、剛開始以為是配置的原因,因此初始化git config
-
git config -- list //查看當前的config配置
-
git config -- global user.name "youruser" //修改用戶名
-
git config -- global user.email "你的郵箱" //修改為你的郵箱
這部分配置的是你個人的用戶名稱和電子郵件地址。這兩條配置很重要,每次 Git 提交時都會引用這兩條信息,說明是誰提交了更新,所以會隨更新內容一起被永久納入歷史記錄
關於git config,建議參考文檔git config 文檔
2、重新使用git pull 拉取數據,此時顯示正常
三、git push 報錯:
-
Access denied
-
exec request failed on channel 0
-
fatal: Could not read from remote repository.
-
-
Please make sure you have the correct access rights
-
and the repository exists.
1、先去看看.ssh有問題沒
-
1、進入.ssh目錄
-
cd ~/.ssh
-
2、查看此時下面的公鑰私鑰
-
ls //看看有沒有 id_rsa id_rsa_pub 等文件
-
3、如果存在改文件,說明此時是配置好的。我們可以復制id_rsa_pub文件中的公鑰,去碼雲上面,添加SSh公鑰
如圖所示從新添加個公鑰試試。
2、繼續git push
還是報錯:
-
Access denied
-
exec request failed on channel 0
-
fatal: Could not read from remote repository.
-
-
Please make sure you have the correct access rights
-
and the repository exists.
這下ssh也沒問題了,再報錯,那是有八九還是配置的原因
1)進入git的配置文件所在
-
1、cd .git
-
2、vim config
2)着重查看url部分
就是箭頭指向這里,我這邊是因為url的問題。和碼雲上克隆的地址不一樣,所以才造成提交失敗。
路徑改為一致的路徑。此時執行git push,發現執行成功。
總體來說,這部分的內容還是挺多的,排錯過程試了很多方法。大家遇到錯誤也多找找原因,有可能就是很簡單的問題,但是卻浪費我們大量的時間。
轉載地址:https://blog.csdn.net/belalds/article/details/80485160