git push 远程仓库时,出现以下类似错误,'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
远程仓库:origin
远程分支:master
本地分支:master
完整报错代码可能是这样的:
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.
git pull
If you wish to set tracking information for this branch you can do so with:
git branch --set-upstream-to=origin/ master
原因是没有指定本地 master
分支和远程 origin/master
的连接,这里根据提示:
git branch --set-upstream-to=origin/master master
解决方案:因为远程仓库新建时,有LIENCE,由于本地仓库和远程仓库有不同的开始点,也就是两个仓库没有共同的commit出现,无法提交,此时我们需要allow-unrelated-histories
。也就是我们的 pull 命令改为下面这样的:
git pull origin master --allow-unrelated-histories
如果设置了默认分支,可以这样写:
git pull --allow-unrelated-histories
然后 git push 就可以了。