两个git仓库合并

3/3/2022 git

现在有两个 gitee 地址,需要合并,一个是suantaichaorou/master,一个是yunmai/master

# 一、首先先拉取一个仓库的代码

  git pull https://gitee.com/suantaichaorou/yunmai.git
1

# 二、接着在添加另外一个仓库并取别名为 yunmai

  git remote add yunmai https://github.com/yunmai/yunmai.git
1

# 三、抓取 yunmai 这个仓库

  git fetch yunmai
  From https://github.com/yunmai/yunmai.git
    * [new branch]      master     -> yunmai/master
1
2
3

# 四、切换到 yunmai 分支上,并命名为 asd

  git checkout -b asd yunmai/master

  Switched to a new branch 'asd'
  Branch 'asd' set up to track remote branch 'master' from 'yunmai'.

  //查看一下所有分支
  $ git branch
  * asd
    master
1
2
3
4
5
6
7
8
9

# 五、我们需要把 asd 合并到 master 上去,先切换到 master

  git checkout master
1

# 六、合并

  git merge asd
1

# 合并完成之后会出现很多冲突,需要在本地代码中解决冲突,然后在提交到 master 中去

  git push https://gitee.com/suantaichaorou/yunmai.git master //上传到远程库
1

fatal: refusing to merge unrelated histories 错误

在执行 merge 合并的时候出现 fatal: refusing to merge unrelated histories 错误。这个错误可能会在 git pull 或者 git push 中都有可能会遇到,意思是两个没有取得关系。

在操作命令后面加 --allow-unrelated-histories 即可

  git merge asd --allow-unrelated-histories
1

# 最后就是正常 push 即可

上次更新: 3/3/2022, 10:26:15 PM