Git push 被拒絕是Git使用過程中常見的問題之一,本文將從多個方面介紹Git push 被拒絕的常見原因及解決方法。
一、導致git push 被拒絕的原因及解決方法
Git push 被拒絕通常是由以下原因造成的:
1、本地分支與遠程分支不一致;
2、權限問題;
3、網絡問題;
4、其他未知錯誤。
1、本地分支與遠程分支不一致
當我們在本地提交代碼後,執行git push命令時,可能會出現下列提示:
error: failed to push some refs to 'git@github.com:xxxx/xxxx.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
這時,我們需要先執行git pull 操作,將遠程分支上的代碼合併到本地,處理成功後,再執行git push。
2、權限問題
當我們在執行git push時,經常會遇到權限問題,主要原因是我們沒有相應的權限提交代碼,解決方法如下:
- 1、檢查是否添加了公鑰或私鑰;
- 2、檢查是否有該項目的寫權限;
- 3、檢查是否在合適的分支上。
3、網絡問題
網絡問題也是導致git push 被拒絕的主要原因之一,我們可以通過以下方式解決:
- 1、切換網絡環境;
- 2、檢查本地Git配置文件是否正確,配置文件位置在 ~/.gitconfig;
- 3、運行命令
git config --global http.postBuffer 524288000
,擴大post buffer大小。
4、其他未知錯誤
如果出現了未知錯誤,我們可以通過以下方法進行解決:
- 1、首先查看具體的錯誤信息,例如找不到倉庫等錯誤,可以參考具體錯誤信息解決方案;
- 2、嘗試通過刪除本地倉庫重新克隆的方式解決,執行以下命令即可:
rm -rf .git
git init
git remote add origin git@github.com:xxxx/xxxx.git
git pull origin master --allow-unrelated-histories
git push -u origin master
二、小標題2
1、文字闡述內容1
2、文字闡述內容2
3、文字闡述內容3
三、小標題3
1、文字闡述內容1
2、文字闡述內容2
3、文字闡述內容3
原創文章,作者:SGMJH,如若轉載,請註明出處:https://www.506064.com/zh-hant/n/373082.html