Git-问题fatal: refusing to merge unrelated histories
问题出现: 本地已经一个仓库A,没有关联远程仓库,因此,从github创建了一个远程仓库B,并增加了一个README文件。现在要将二者进行关联: 在本地执行:
1
git remote add origin https://github.com/zjmmjzzjm/pythontips
控制台输出:
1
2
3
4
5
6
7
8
9
dwarning: no common commits
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), done.
From https://github.com/zjmmjzzjm/pythontips
* branch master -> FETCH_HEAD
* [new branch] master -> origin/master
fatal: refusing to merge unrelated histories
可以看到 有一行 fatal: refusing to merge unrelated histories
,表明远程分支并未成功和本地分支进行合并。意思是不允许两个不相关的分支进行合并,可以强制执行如下指令:
1
git pull origin master --allow-unrelated-histories
控制台输出:
1
2
3
4
5
6
From https://github.com/zjmmjzzjm/pythontips
* branch master -> FETCH_HEAD
Merge made by the 'recursive' strategy.
README.md | 2 ++
1 file changed, 2 insertions(+)
create mode 100644 README.md
此时一切正常,执行即可将本地代码推送到云端
1
git push origin master