問題一
問題描述
執行 git push origin 時報錯,如下:
解決辦法
執行
git remote add code-na2 [email protected]:code-na2/mos-mss.git
即發現遠程倉庫有問題,所以重新關聯到新的遠程倉庫。
解決過程
- 查看本地配置
git config -- list 查看當前項目下所有 git 相關配置
配置結果:
credential.helper=osxkeychain
user.name=趙娜
user.email=[email protected]
url.https://.insteadof=git://
url.git://.insteadof=https://
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
core.ignorecase=true
core.precomposeunicode=true
remote.origin.url=https://github.com/gitna2/mos-mss.git
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
branch.master.remote=origin
branch.master.merge=refs/heads/master
branch.feature-5721399.remote=origin
branch.feature-5721399.merge=refs/heads/master
remote.upstream.url=https://github.com/gitna2/mos-mss.git
remote.upstream.fetch=+refs/heads/*:refs/remotes/upstream/*
即包含用戶名、郵箱、所有關聯的遠程倉庫 remote(這裏是origin、upstream)、及對應倉庫下分支。
從結果發現遠程倉庫配置url有問題,故可刪除現有錯誤配置,重新設置遠程倉庫。
- 重新關聯現有遠程倉庫相關設置或直接新建一個遠程配置
先刪除現有 origin 關聯(直接新建遠程配置時不用):
git remote remove origin
再添加新的遠端倉庫並設置別名,這裏使用別名 code-na2:
git remote add code-na2 [email protected]:code-na2/mos-mss.git
- 查看本地倉庫下 branch
git branch -r
發現沒有關聯分支,所以要拉取代碼:
git fetch code-na2
這樣,再執行:
git push origin feature-5721399
就成功了
涉及關鍵命令
git config -- list 查看當前項目下所有 git 相關配置
git remote remove origin 刪除現有遠端倉庫關聯
git remote add code-na2 [email protected]:code-na2/mos-mss.git 添加遠端倉庫關聯
git fetch code-na2 從遠端拉去分支
git branch -r 本地所有倉庫下 branch