git无法pull仓库refusing to merge unrelated histories

本文详细介绍如何将本地未关联远程库的项目成功与新建的远程库进行关联,并解决了关联过程中遇到的多个常见问题,包括分支配置、历史记录合并等。

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

本地写了一个项目,此时还没有和远程库关联,项目开始初始化差不多了,然后在gitee上建一个库做关联,存放项目。
首先,
本地库和远程库做关联:git remote add git@gitee.com:******.git
做好关联之后以为就可以提交了,但是你错了,因为远程项目跟本地项目不一致,外加你们的分支还没有关联
觉得使用git pull就可以更新,结果报错:

You asked to pull from the remote 'origin', but did not specify
a branch. Because this is not the default configured remote
for your current branch, you must specify a branch on the command line.

解决方法是,打开.git下得config文件夹添加如下:

[branch "master"]
    remote = origin
    merge = refs/heads/master

origin是你自己定义得远程库得名字
这个时候应该可以pull了吧,结果还是不对,报错:

fatal: refusing to merge unrelated histories

因为他们是两个不同的项目,要把两个不同的项目合并,git需要添加一句代码:–allow-unrelated-histories
执行:

git pull gitee master --allow-unrelated-histories

这个时候我们就可以愉快的push了。
参考地址:http://stackoverflow.com/questions/4847101/git-which-is-the-default-configured-remote-for-branch
参考博文:https://blog.youkuaiyun.com/lindexi_gd/article/details/52554159
参考博文:https://blog.youkuaiyun.com/u012028371/article/details/52384882
这个博文这儿有一张图,博主对git理解比较深:https://blog.youkuaiyun.com/kindle_code/article/details/52196511

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值