git幾個小問題
阿新 • • 發佈:2021-10-27
Could not read from remote repository.Please make sure you have the correct access rights
最近有做到一道很有意思的git練習題
-
將oops_2021
fork
到自己的專案裡。 -
將
fork
後的遠端倉庫clone
下來,並在./src
裡建立一個資料夾,資料夾名為 Github 的使用者名稱,並在資料夾記憶體放一個檔案。 -
存放的檔案內容可以是(檔案大小不宜太大):其他題目的檔案,可選任務的程式碼檔案
-
將修改後的專案提交到你
fork
的遠端倉庫。 -
當你確定你不會再更改遠端倉庫的時候,提交合並請求到主專案。(當然你提交後還是可以修改再次提交)
當我做好後滿心歡喜的使用Terminal合併提交到遠端倉庫上時:
git push origin報錯:
Could not read from remote repository.Please makesure you have the correct access rights
首先git輸入命令:$ ssh-keygen -t rsa -C "[email protected]"(忘了註冊郵箱可以去github的account上找一下)
如果執行成功,返回:
Generating public/private rsa key pair. Enter file in which to save the key (/Users/username/.ssh/id_rsa):
開啟github官網登陸自己的賬戶,進入設定,點選SSH and GPG keys開啟該頁面,把剛才複製的貼上在key中(mac上可以用command+空格跳查剛剛生成的檔案)
title可以不填,最後點選add ssh key。在git中輸入:ssh -T [email protected],輸入命令yes,回車。
同時可能會有如下問題
fatal: remote origin already exists
解決:
1、先刪除遠端Git倉庫 git remote rm origin 2、再新增遠端Git倉庫 git remote add origin url(要新增的遠端倉庫地址)
本以為就這樣結束了,倉庫又出現了問題
git push origin 時遇到報錯如下: fatal:'origin' does not appear to be a git repository fatal:Could not read from remote repository
解決方案
0、cd 本地分支 1、git branch ——*master 只顯示master 2、git remote –v ——若什麼都沒有,那就有問題了 3、git remote add origin ssh://git@***.git(地址) 4、git fetch origin 格式為From ssh://gitlab.-》origin 再次檢查遠端倉庫,顯示對應的clone地址 5、git remote –v 6、git branch –a