0

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.

Hugo y
  • 1,421
  • 10
  • 20
Kobek
  • 1,149
  • 6
  • 18
  • 40
  • You are going in the wrong direction. You should work on a single repo, your local changes are still your own but you should be integrating with each other's changes frequently when pushing back to the remote. You can use branches if you really want to, but with only two of you that's probably not necessary or even helpful. – jonrsharpe Mar 26 '17 at 20:56

2 Answers2

1

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?

ElpieKay
  • 27,194
  • 6
  • 32
  • 53
  • Why not?.. Cause I'm not that experienced with git and still learning how to use it. I tried to git fetch my repos, and it does fetch some changes, but how do I get them to save in Repo C (gitt add . / git commit /git push all say there are no new changes to my repo) – Kobek Mar 27 '17 at 14:05
0

Take a look at the git submodules feature: https://git-scm.com/book/en/v2/Git-Tools-Submodules

Regards

Andoni

Andoni
  • 171
  • 9
  • I think that you should think twice before using submodules because that is not as easy as we think, especially when developers are not experienced with git. Before choosing this solution, I highly advice to think if monorepo is not the solution... – Philippe Mar 26 '17 at 22:38
  • Thanks to both of you. I'll do some reading on both git submodules and monorepo :) – Kobek Mar 27 '17 at 14:06