没有指定本地 master 分支和远程 origin/master 的连接

  git push 远程仓库时,出现以下类似错误,'Note about fast-forwards' in 'git push --help' for details.

 
  1. To https://github.com/SeshinWei/django.git

  2. ! [rejected] master -> master (non-fast-forward)

  3. error: failed to push some refs to 'https://github.com/SeshinWei/django.git'

  4. hint: Updates were rejected because the tip of your current branch is behind

  5. hint: its remote counterpart. Integrate the remote changes (e.g.

  6. hint: 'git pull ...') before pushing again.

  7. hint: See the 'Note about fast-forwards' in 'git push --help' for details.

错误:non-fast-forward
远程仓库:origin
远程分支:master
本地分支:master

完整报错代码可能是这样的:

 
  1. There is no tracking information for the current branch.

  2. Please specify which branch you want to merge with.

  3. See git-pull(1) for details.

  4. git pull <remote> <branch>

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

  6. 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 就可以了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值