# 本地初始化仓库 + 远程仓库

本地合并时遇到 refusing to merge unrelated histories 的错误

如果 git merge 合并的时候出现 refusing to merge unrelated histories 的错误,原因是两个仓库不同而导致的,需要在后面加上 ** --allow-unrelated-histories ** 进行允许合并,即可解决问题

如果还不能解决问题,就把本地的 remote 删除,重新 git remote add 添加远程仓库,再按上面的方法来,问题解决。

git init

G:\GoLandProjects\go_learn>git pull
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), 893 bytes | 59.00 KiB/s, done.
From github.com:ShanJianSoda/golang_learn
 * [new branch]      main       -> origin/main
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.

    git pull <remote> <branch>

If you wish to set tracking information for this branch you can do so with:

    git branch --set-upstream-to=origin/<branch> main


G:\GoLandProjects\go_learn>git branch --set-upstream-to=origin/main main
branch 'main' set up to track 'origin/main'.

G:\GoLandProjects\go_learn>git pull
fatal: refusing to merge unrelated histories

G:\GoLandProjects\go_learn>git pull --allow-unrelated-histories
Merge made by the 'ort' strategy.
 README.md | 2 ++
 1 file changed, 2 insertions(+)
 create mode 100644 README.md

G:\GoLandProjects\go_learn>git push
Enumerating objects: 6, done.
Counting objects: 100% (6/6), done.
Delta compression using up to 16 threads
Compressing objects: 100% (4/4), done.
Writing objects: 100% (5/5), 1.06 KiB | 1.06 MiB/s, done.
Total 5 (delta 0), reused 0 (delta 0), pack-reused 0 (from 0)
To github.com:ShanJianSoda/golang_learn.git
   d130b38..e33a5c1  main -> main

本地分支更名

git branch -m oldname newname