简体   繁体   English

Git如何制作一个主仓库来跟踪另外两个仓库

[英]Git How to make a master repo that tracks two other repos

We are working on an app and use Github to hold and version our code. 我们正在开发一个应用程序,并使用Gi​​thub来保存和版本化我们的代码。

Currently, we are 2 people each working on a seprate repo ( RepoA and RepoB ). 目前,我们有2个人分别从事单独的 仓库RepoARepoB )。

We decided that it would be best if we had 1 master repo to hold the complete app, but we also want to continue working on our separate repos on our own. 我们认为最好是拥有1个主仓库来保存完整的应用程序,但我们也想继续自己开发单独的仓库。 I followed this tutorial to merge both our repos into a new master repo ( RepoC ). 我按照教程将两个仓库都合并到一个新的主仓库RepoC )中。

Everything worked perfectly but now we have the issue where changes to RepoA or RepoB don't reflect in RepoC and vice-versa. 一切运行正常,但是现在我们遇到了一个问题,即对RepoARepoB的更改不会反映在RepoC中 ,反之亦然。

So I was wondering... Is there any way, that we can tell RepoC to " track " RepoA and RepoB for changes, and sync with them when needed. 所以我想知道...有什么办法,我们可以告诉RepoC跟踪RepoARepoB进行更改,并在需要时与它们同步。

If the above is not possible, is there atleast a way where we can contribute to our own repos and then do something like " git fetch RepoA , git fetch RepoB " on our master RepoC so that it can reflect the changes we've made. 如果上述方法不可行,那么是否存在至少一种方法,我们可以为自己的存储库做出贡献,然后在主RepoC上执行诸如“ git fetch RepoAgit fetch RepoB ”之类的操作,以便它可以反映我们所做的更改。

In theory, one repo can track infinitive number of repos by different remotes and branches. 从理论上讲,一个仓库可以跟踪不同远程和分支机构的仓库的无限数量。

Suppose RepoA's url is git://host/repoa.git and RepoB's is git://host/repob.git . 假设RepoA的网址是git://host/repoa.git而RepoB的网址是git://host/repob.git Each has three branches, master , feature , and release , for example. 每个都有三个分支,例如masterfeaturerelease

In RepoC, we can create two remotes. 在RepoC中,我们可以创建两个遥控器。

git add remote origina git://host/repoa.git
git add remote originb git://host/repob.git

And then 接着

git fetch --all

All branches in both repos can be tracked. 可以跟踪两个存储库中的所有分支。

However, this approach has some problems. 但是,这种方法存在一些问题。

  1. You can checkout only one of these branches which means you cannot have 2 repos' codes in the same working tree. 您只能检出这些分支之一,这意味着您不能在同一工作树中使用2个回购代码。
  2. When you checkout/create local branches from the remote tracking branches, you need to name them carefully not to confuse yourself. 从远程跟踪分支签出/创建本地分支时,需要仔细命名它们,以免混淆自己。
  3. When RepoA and RepoB have tags with the same name, only one of them can be fetched into RepoC. 如果RepoA和RepoB具有相同名称的标签,则只能将其中一个标签提取到RepoC中。

Since you have merged them into RepoC, you could create two remotes and track both in addition. 由于已将它们合并到RepoC中,因此您可以创建两个遥控器并同时跟踪两个遥控器。 But why not use two repos to track them? 但是,为什么不使用两个存储库来跟踪它们呢?

Take a look at the git submodules feature: https://git-scm.com/book/en/v2/Git-Tools-Submodules 看看git子模块功能: https : //git-scm.com/book/en/v2/Git-Tools-Submodules

Regards 问候

Andoni 安多尼

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM