git 无法push远程仓库 Note about fast-forwards 问题解决

  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 <remote> <branch>

If you wish to set tracking information for this branch you can do so with:

    git branch --set-upstream-to=origin/<branch> 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 就可以了。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值