今天將項目修改了一部分,然后用 git push origin master
向遠程倉庫推送的時候報如下錯誤:
error: failed to push some refs to 'https://github.com/ZJyoung1997/JZShop.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.
原因是遠程倉庫中的文件和我們本地的倉庫有差異,例如你的遠程倉庫有個文件Readme. md,但是本地倉庫卻沒有,就可能會出現這種情況。 我的就是遠程倉庫中有Readme. md文件,而本地倉庫中沒有該文件造成的。還有就是因為平時在協會中,用協會電腦開發,回到寢室后又會用自己的電腦開發,這可能也是導致這種問題的原因。這種情況有解決辦法,就是將本地倉庫直接干掉,然后重新從遠程clone一個,但是這樣顯然太麻煩了,可以用合並分支的方法
解決辦法:
git pull --rebase origin master
git pull命令用於從另一個存儲庫或本地分支獲取並集成(整合),取回遠程主機某個分支的更新,再與本地的指定分支合並。
fatal: 'master' does not appear to be a git repository
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
用 git pull origin master --allow-unrelated-histories
解決
原文地址:解決error: failed to push some refs to 'xxxx'