1. 程式人生 > 實用技巧 >git:Please make sure you have the correct access rights and the repository exists.問題解決

git:Please make sure you have the correct access rights and the repository exists.問題解決

問題描述:把本地庫裡的內容推送到遠端庫的時候出錯?

git push -u origin master
fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists;

這個問題當時真是困擾了我很久,後來看了別人的部落格豁然開朗了。

其實是公鑰出了問題,要先設定使用者名稱和郵箱再重新生成ssh公鑰即可。

1.首先我得重新在git設定一下身份的名字和郵箱 進入到需要提交的資料夾底下(因為直接開啟git Bash,在沒有路徑的情況下,根本沒!法!改!剛使用git時遇到的坑。。。)

git config --global user.name "yourname"

git config --global user.email "[email protected]"

這裡我覺得郵箱地址最好與你GitHub上的郵箱地址一致。

2.刪除.ssh資料夾(直接搜尋該資料夾)下的known_hosts(手動刪除即可,不需要git)

ssh在C盤裡面,直接搜尋即可。(刪除之後不要關閉,還會用到)

3.git輸入命令

$ ssh-keygen -t rsa -C "[email protected]"(請填你設定的郵箱地址)

然後一直回車即可。
然後系統會自動在.ssh資料夾下生成兩個檔案,id_rsa和id_rsa.pub,用記事本開啟id_rsa.pub將全部的內容複製

4.開啟https://github.com/,登陸你的賬戶,進入設定,進入ssh設定


在key中將剛剛複製的貼上進去

點選add ssh key

重新輸入git命令

  1. $ git remote rm origin 刪除遠端庫
  2. git remote add origin [email protected]:michaelliao/learngit.git 重新關聯遠端庫
  3. git push -u origin master 再次把庫裡面的內容推到遠端庫裡面。
    ok!問題解決了!!!

csdn地址:https://www.liaoxuefeng.com/wiki/896043488029600/898732864121440