1

I have a question regrading intertwined repositories.

I have a repo, lets call it common_repo.

common_repo holds code which is relevant to most of my other repos, and I wish to pull it whenever I pull other repositories.

We've considered submodules, but as far as I understand this will create numerous copies of the common repo on my machine. This is undesireable as I may have differnet versions on my computer of the same files according to when I last pulled the dependent repo, which could lead to confusion.

Another alternative would be using some custom scripts such as sggested here. However this is not cross paltform (we have multiple developers working on different OS's), requires deployment on each machine, and doesn't play well git GUI clients such as smartgit or source tree.

Is there a better solution which we haven't considered?

Yair M
  • 450
  • 4
  • 12

1 Answers1

2

You can update all git repositories in a directory with a bash command, as you mentioned

find . -maxdepth 3 -name .git -type d | rev | cut -c 6- | rev | xargs -I {} git -C {} pull

Credit: https://medium.com/@codenameyau/updating-multiple-repos-with-one-command-9768c8cdfe46

Another option I can propose to you would be to explore the post-merge git hook, where you could accomplish something similar to the above on git pull. Any language, compiled or interpreted can be used in a git hook as long as the appropriate interpreter is available on the system. This may be a good resource: https://git-scm.com/docs/githooks

buttface64
  • 143
  • 5
  • Thanks for the response. This line of thought is similar to what the second suggetion I quoted. However I wish not to set up bash aliases on each of the developers machines, and as stated, prefer a solution which can be invoked within git GUI clients – Yair M Mar 21 '20 at 10:06
  • Did you see my proposal regarding git hooks? What are your thoughts there? – buttface64 Mar 21 '20 at 10:08
  • Sorry for my oversight. This sounds promising. Do you suggest using the [post-merge](https://git-scm.com/docs/githooks#_post_merge) hook? If used, will this work also in my GUI clients, since behind the dcenes they're using standard git commands? – Yair M Mar 21 '20 at 10:20
  • For Windows PowerShell version: https://stackoverflow.com/a/48926766/10158227 – Audwin Oyong Jul 07 '22 at 09:37