? git push 遠(yuǎn)程倉庫時,出現(xiàn)以下類似錯誤,'Note about fast-forwards' in 'git push --help' for details.
To https://github.com/SeshinWei/django.git
! [rejected]? ? ? ? master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/SeshinWei/django.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
錯誤:non-fast-forward
遠(yuǎn)程倉庫:origin
遠(yuǎn)程分支:master
本地分支:master
完整報錯代碼可能是這樣的:
Thereisno tracking informationforthe current branch.Please specify which branch you want to mergewith.See git-pull(1)fordetails.? ? git pull If you wish to set tracking informationforthis branch you can do sowith:? ? git branch --set-upstream-to=origin/ master
原因是沒有指定本地master分支和遠(yuǎn)程origin/master的連接,這里根據(jù)提示:
git branch --set-upstream-to=origin/master master
解決方案:因為遠(yuǎn)程倉庫新建時,有LIENCE,由于本地倉庫和遠(yuǎn)程倉庫有不同的開始點,也就是兩個倉庫沒有共同的commit出現(xiàn),無法提交,此時我們需要allow-unrelated-histories。也就是我們的 pull 命令改為下面這樣的:
git pull origin master --allow-unrelated-histories
如果設(shè)置了默認(rèn)分支,可以這樣寫:
git pull --allow-unrelated-histories
然后 git push 就可以了。