Git - fatal: refusing to merge unrelated histories

将本地代码提交到远程gitHub步骤:

在gitHub上创建仓库

Git - fatal: refusing to merge unrelated histories

1. 现在本地初始化

echo "# spring" >> README.md

git init

git add README.md
2. 本地提交
git commit -m "first commit"

3. 添加远程git

git remote add origin https://github.com/huyanmin/SpringRelate.git

4. 同步远程代码报错了

git pull origin master

原因: 上面新建的仓库中存在一个README.md的文件,git pull 时要将该文件pull到本地来,需要--allow-unrelated-histories

错误:  fatal: refusing to merge unrelated histories

解决办法: git pull origin master --allow-unrelated-histories

运行结果如下:

Git - fatal: refusing to merge unrelated histories

5. 推送本地master去远程master

git push origin master:master
Git - fatal: refusing to merge unrelated histories

搞定啦!!!

其他相关git的命令:

设置远程仓库: git remote set-url origin https://github.com/huyanmin/SpringRelate.git

Error:

Can't Update
        No tracked branch configured for branch 20190412 or the branch doesn't exist.
        To make your branch track a remote branch call, for example,
        git branch --set-upstream-to=origin/20190412 20190412 (show balloon)