Git – GitHub 出現 「Please make sure you have the correct access rights and the repository exists.」
接手專案維護的時候,準備要 git pull 卻出現錯誤
ERROR: Repository not found.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
這是因為使用 ssh 連線到 GitHub 但可能出現 key 遺失或遭受更改的關係,如果不是要自動化處理,我們可以替換成詢問 username 與 password 的模式來解決這個困擾。
# 先確定目前遠端位置
git remote -v
# 如果出現這樣,代表前人用的是 SSH 連線方式
origin git@github.com:{username}/{repo}.git (fetch)
origin git@github.com:{username}/{repo}.git (push)
# 打這行會不給修改
git remote add origin https://github.com/{username}/{repo}.git
# 會說已經存在
fatal: remote origin already exists.
# 所以要打這行,修改為走 https 通道的詢問模式
git remote set-url origin https://github.com/{username}/{repo}.git
# 接著確認一下
git remote -v
# 代表成功替換
origin https://github.com/{username}/{repo}.git (fetch)
origin https://github.com/{username}/{repo}.git (push)
# 接著 pull
git pull
# 就會詢問我們 GitHub 帳號密碼了
Username for 'https://github.com':
參考來源