0

I have a parent git repo with 3 branches in it. I am also using a submodule repo, that has the 3 branches with the same names, and the .gitattributes file in each branch of the parent repo points to the submodules branch of the same name. This is all well and good, but the question I have is, when I do a git checkout BRANCH in the parent repo, I always have to do a git submodule update after, or the files in the submodule directory wont be updated to reflect the correct branch

Is there a simple way to automate this, so that every time I do a checkout the submodule files get updated to reflect the correct branch?

Matthew
  • 952
  • 7
  • 20

1 Answers1

2
git checkout master & git submodule foreach git checkout master

Where master is the name of your chosen branch

You can add a hook post-checkout and do this action whenever you call git checkout automatically. You need to create a file .git/hooks/post-checkout which will look like:

branch=$(git rev-parse --symbolic --abbrev-ref $1)
git submodule foreach git checkout $branch

Hope this will help

Piotr Pasich
  • 2,639
  • 2
  • 12
  • 14
  • Ok, can I alias this in a way that any of the other devs who clone the repo will have access to the alias? Cause the guy I work with is not going to remember to do that every time he does a checkout – Matthew Feb 14 '17 at 20:43
  • I've updated my answer by git hooks . If that helps please remember to mark the answer as solved :) – Piotr Pasich Feb 14 '17 at 21:05