在 Git 中合并两个远程存储库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1767980/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 03:57:15  来源:igfitidea点击:

Merging two remote repositories in Git

gitgit-merge

提问by Readon Shaw

I want to merge two remote repositories in Git.

我想在 Git 中合并两个远程存储库。

One is mainstream repository, which I do not have write permission. I want to track its master branch.

一个是主流存储库,我没有写权限。我想跟踪它的主分支。

The other is maintained by us, I have full rights on it.

另一个由我们维护,我拥有完全的权利。

I want to track the mainstream code. At the same time, our modification would be recorded in my remote repository.

我想跟踪主流代码。同时,我们的修改会记录在我的远程仓库中。

How do I do this?

我该怎么做呢?

回答by VonC

I would recommend:

我会推荐:

  • cloning yourRemoteRepo(that way, you can easily pull/push from that repo)
  • adding mainstreamRepoas a remote and fetch its branch, then track the one which interest you

    git clone git://yourRemoteRepo
    git remote add mainStreamRepo http://mainStreamRepo
    git fetch mainStreamRepo
    git checkout -b mainStreamMaster mainStreamRepo/master
    git checkout master
    
  • 克隆yourRemoteRepo(这样,您可以轻松地从该存储库中拉/推)
  • 添加mainstreamRepo为远程并获取其分支,然后跟踪您感兴趣的分支

    git clone git://yourRemoteRepo
    git remote add mainStreamRepo http://mainStreamRepo
    git fetch mainStreamRepo
    git checkout -b mainStreamMaster mainStreamRepo/master
    git checkout master
    

From there, you can

从那里,你可以

  • merge mainStreamMasterto your master,
  • or rebase your masteron top of mainStreamMaster(in order to integrate the full history of mainStreamMasterinto your masterbranch)
  • then make some evolutions to master(or to a topic-specific branch) that you can push to yourRemoteRepo.
  • 合并mainStreamMaster到您的master,
  • 或重新建立您master的基础mainStreamMaster(以便将 的完整历史记录集成mainStreamMaster到您的master分支中)
  • 然后对master(或特定主题的分支)进行一些演变,您可以将其推送到yourRemoteRepo.