[英]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. 我们正在开发一个应用程序,并使用Github来保存和版本化我们的代码。
Currently, we are 2 people each working on a seprate repo ( RepoA and RepoB ). 目前,我们有2个人分别从事单独的 仓库 ( RepoA和RepoB )。
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. 一切运行正常,但是现在我们遇到了一个问题,即对RepoA或RepoB的更改不会反映在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 “ 跟踪 ” RepoA和RepoB进行更改,并在需要时与它们同步。
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 RepoA , git 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. 每个都有三个分支,例如master , feature和release 。
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. 但是,这种方法存在一些问题。
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.