修改问题:如何将远程git存储库配置为现有本地存储库的新分支,其单个分支已链接到不同的远程存储库。
我有两个git存储库(项目)托管在两个不同的站点(github和一个Intranet站点)。
它们彼此相似,因为它们从相同的基本文件夹开始。我想将这两个项目合并为一个单独的git项目,以便
答案 0 :(得分:2)
查看之前的Stackoverflow question我找到了实现此目标的方法follows
cd到链接到github repo的本地文件夹
cd ~/projects/prj_a
更新.git / config以限制分支映射,以便本地“master”分支指向github的“主”分支
[remote "origin"]
url = git@github.com:user/prj_a.git
fetch = +refs/heads/master:refs/remotes/origin/master
添加新的git远程
git remote add intranet git@intranet_server:user/intranet_project.git
更新.git / config,以便将新的git remote提取到新的远程分支
[remote "intranet"]
url = git@intranet_server:user/intranet_project.git
fetch = +refs/heads/master:refs/remotes/intranet/intranet_branch
从新的远程仓库中获取分支
git fetch intranet
将新远程分支检入新的本地分支。这也将切换到新分支。
git checkout -b intranet_branch intranet/intranet_branch
合并指向github的主分支
git merge master
解决合并冲突并提交
从intranet_branch推送到intranet_repo的主分支
git push intranet intranet_branch
再次测试一切
$ git checkout master
Switched to branch 'master'
Your branch is up-to-date with 'origin/master'.
$ git pull origin master
....
* branch master -> FETCH_HEAD
Already up-to-date.
$ git push origin master
Everything up-to-date
$ git checkout intranet_branch
Switched to branch 'intranet_branch'
Your branch is up-to-date with 'intranet/intranet_branch'.
$ git pull intranet intranet_branch
...
* branch intranet_branch -> FETCH_HEAD
Already up-to-date.
$ git push intranet intranet_branch
Everything up-to-date