0

I have a git repository which is used across a team of 10+ developers. I have a few git submodules added into my repository. The submodules can of course be checked out by the following command.

git submodule update --init

But if I want that the submodule update to happen automatically when someone does a git pull, is it feasible? How can I do this?

Is there something I can do with git hooks ?

TheWaterProgrammer
  • 7,055
  • 12
  • 70
  • 159

1 Answers1

0

You only need to update once after cloning the project (unless you're adding new submodules). If you want to get all changes from each of the submodules like you would with pull, you can use the following command:

git pull && git submodule foreach git pull

This will pull on the main repository, then pull on each submodule associated with the main repository.

Or, you can set up an alias in your .bashrc file to do this automatically. For example, I have:

alias git-pull='git pull && git submodule foreach git pull'
J. Titus
  • 9,535
  • 1
  • 32
  • 45
  • Is it possible to do something once at the repository level to make this work for all developers ? – TheWaterProgrammer Jan 27 '17 at 14:56
  • the answer you provided works local to my machine. but I am looking for something at repository level. may be something with git-hooks ? – TheWaterProgrammer Jan 27 '17 at 15:04
  • 1
    You could share the `.bashrc` file. Server-side Git hooks will only work with the `push` action: https://www.atlassian.com/git/tutorials/git-hooks#server-side-hooks. Or you can manage client-side hooks as explained in this SO question: http://stackoverflow.com/questions/427207/can-git-hook-scripts-be-managed-along-with-the-repository. – J. Titus Jan 27 '17 at 16:55