1、场景
本地新建仓库并进行了一部分开发,之后关联远端仓库,想要将代码提交到仓库中,但是第一次git pull 的时候没有通过 git pull <remote> <branch>去关联分支,之后就会出现上述无关联的提醒,
常见的现象如下:
- 第一次git pull 只能拉取分支,但是不能拉取代码,之后git pull提示fatal: refusing to merge unrelated histories
- git push 提示fatal: refusing to merge unrelated histories
- git merge 也会提示fatal: refusing to merge unrelated histories
2、解决
2.1:git pull 加上定义的远端仓库名和对应的分支(分支名相同)
git pull
git pull <remote> <branch>
eg: git pull myblog master
2.2允许无关联历史情况下的操作--allow-unrelated-histories
先git pull --allow-unrelated-histories拉取一下代码,之后的git操作就不会提示这个了