简体   繁体   中英

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.

Currently, we are 2 people each working on a seprate repo ( RepoA and 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. I followed this tutorial to merge both our repos into a new master repo ( RepoC ).

Everything worked perfectly but now we have the issue where changes to RepoA or RepoB don't reflect in RepoC and vice-versa.

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.

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.

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 . Each has three branches, master , feature , and release , for example.

In RepoC, we can create two remotes.

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. 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.

Since you have merged them into RepoC, you could create two remotes and track both in addition. 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

Regards

Andoni

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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