git refusing to merge unrelated histories
本地项目添加远程仓库:
$ git remote add new_origin https://github.com/user/repo.git
# Set a new remote
$ git remote -v
# Verify new remote
> new_origin https://github.com/user/repo.git (fetch)
> new_origin https://github.com/user/repo.git (push)
上面new_origin
就是远程仓库的别名,随便取。因为仓库在创建时会生成一个readme
文件,所以我要在本地先同步下代码:
git pull new_origin master
这时就会报如下错误:
From https://github.com/user/repo
* branch master -> FETCH_HEAD
fatal: refusing to merge unrelated histories
默认情况下,git认为这是两个不同的项目,没有关联所以禁止合并,解决办法就是在后面加上--allow-unrelated-histories
,
git pull new_origin master --allow-unrelated-histories
这样就成功了。
参考: