Git如何合并两个仓库的代码

683 阅读1分钟

Git如何合并两个仓库的代码

应用场景

本地有一个仓库A,想用另一个仓库B的分支代码。也就是说我想要合并两个仓库的代码,应该如何操作

1.先查看本地现有的仓库A的git地址

git remote -v
origin  http://gitlab.com/xxx1.git (fetch)
origin  http://gitlab.com/xxx1.git (push)

2.将仓库A中加入仓库B的git地址

git remote add 仓库B的名称 仓库B的git地址
git remote add b http://gitlab.com/xxx2.git; 

3.拉取仓库B的远端地址,但是不会在本地新建分支

git fetch b

4.再次查看git remote -v

origin  http://gitlab.com/xxx1.git (fetch)
origin  http://gitlab.com/xxx1.git (push)
b       http://gitlab.com/xxx2.git (fetch)
b       http://gitlab.com/xxx2.git (push)

5.选择自己想要拉取的分支

这里可能有冲突,注意解决一下

git merge 仓库B的地址/仓库B的某一分支
git merge b/master
注意:这里可能有冲突,自己解决一下就行

6.最后删除仓库B的git地址

git remote rm b