git 报错non-fast-forward,以及fatal: refusing to merge unrelated histories

当尝试将本地git仓库合并到远程仓库时,遇到non-fast-forward和refusing to merge unrelated histories错误。问题在于两者历史记录无关。解决方法是在git pull命令后添加参数--allow-unrelated-histories,使不相关的历史能够合并。在成功合并本地内容为A+B后,需先提交改动,然后执行git push以推送更新到远程仓库。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

问题描述:

在github上远程仓库main分支上创建了一些代码,想把本地仓库的main分支上的内容推入远程仓库,将二者合并,但是出现了错误:

 ! [rejected]        main -> main (non-fast-forward)
error: failed to push some refs to 'github.com:sherlyxoxo/frontend-notebook.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.

 Integrate the remote changes (e.g. 'git pull ...') before pushing again.

这里提示了要用git pull命令,将远程仓库里的最新代码拉到本地来,再将本地的推过去

(也有人推荐为了更安全,使用git fetch + git merge 代替git pull的,这两种办法都行的,有的人到这里问题就解决了)

但是我执行了git pull命令后,又报错:fatal: refusing to merge unrelated histories,无法将远程仓库的代码拉到本地来。


原因分析:

可能是这两个仓库

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值