1

I'm working on a project which include multiple git repositories. The folder structure looks something like this;

repo1/
  +
  ---repo2/
  ---repo3/
  ...
  ---repo8/

So, to setup my development environment, I would need to run something like;

git clone http://path_to_git_repo.git top_folder
cd top_folder
git checkout tags/release34
git clone http://path_to_another_repo.git subfolder1
cd subfolder1
git checkout tags/release55
cd ..
git clone http://path_to_another_repo.git subfolder2
cd subfolder2
git checkout tags/rel-44-abc

... etc

A week or so later, different teams would push their own updates/tags and I'd need to re-synchronize by doing something like this;

cd top_folder
git checkout tags/release44
cd subfolder1
git checkout tags/release-bignewfeature
cd ..
cd subfolder1
git checkout tags/release-reverting_tosomethingelse
cd ..

... etc

Doing the whole re-synchronizing is very ... repetitive and tiresome. Does anyone have any suggestions on how I could make things easier for myself?

I've heard (and tried) the mr tool, but it will only update to the latest HEAD version of a repo while I need to just be updating to certain tags.

chronodekar
  • 2,616
  • 6
  • 31
  • 36

2 Answers2

0

You should consider using git submodules for that, which avoids the all tags/synchronization steps.

Your parent repo repo1 simply reference a collection of fixed SHA1, one for each submodule repos.

A week or so later, different teams would push their own updates/tags

You can make each submodule follow a branch, which means the resynchronization would be:

git submodule update --remote
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Hmm... let me checkout submodules. Thanks! – chronodekar Feb 12 '15 at 07:37
  • @chronodekar note: for the branch, the developers can chose a dedicated branch used only to merge the commits that `repo1` (the parent repo) need to follow. Again, that avoid using tags. `repo1` just follows that branch for each submodule, ensuring that those submodules are updated to the latest commit merged in that special branch. – VonC Feb 12 '15 at 07:43
  • Now, if I understood submodules correctly, it means making changes to the top-level repo. This is not a decision I can make. Sure I can push code changes, but to keep things in sync would now mean up update the main repo. If it were a new project, I could try enforcing this, but as things are, everyone is used to using tags. So, I need a solution which uses that. :( – chronodekar Feb 12 '15 at 07:53
  • @chronodekar you always update a parent repo with submodules: that what submodules are: a precise reference to a SHA1 of another Git repo. You need to record and update the gitlink (http://stackoverflow.com/a/16581096/6309), a special entry in the index of the parent repo (http://stackoverflow.com/a/17442045/6309). – VonC Feb 12 '15 at 07:55
  • @chronodekar trying to use tag will end up having to record somehow the tags that the parent repo is using. That will try and do what submodules are natively doing. – VonC Feb 12 '15 at 07:56
0

A better approach is to use git subtree, It easier to maintain server dependent repository.

You can read more about submodule and subtree here and here

CodeWizard
  • 128,036
  • 21
  • 144
  • 167