Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to force git submodules to be updated?

We have a git repository that depends on code in other git repositories. We use submodules, the usual way, to express this relationship and ensure that the supporting code lives at a standard location within the user's directory structure. Updating the supporting code is straightforward enough:

  • make a change to a submodule
  • commit it
  • push it
  • cd into the main repository
  • commit the change to the submodule
  • push it

The problem comes on the other side. After this sort of change, for other developers to get a complete, consistent set of code they need to execute three commands:

  • git pull (update the main repository)
  • git submodule init (in case any new submodules were added)
  • git submodule update (update the submodules)

It's proven difficult to train developers to do all of these, particularly since in all of our other repositories, which don't contain submodules, the pull is sufficient. The result is developers at times working with code that uses obsolete versions of the submodules, resulting in spurious problems that can be time-consuming to track down. It there any way, other than writing a shell script that does all three commands and insisting "Use this!", to make this more automatic?

like image 200
Mike Schilling Avatar asked Aug 06 '13 21:08

Mike Schilling


Video Answer


1 Answers

You could try and ask your colleagues to:

git config --global fetch.recurseSubmodules on-demand

From git config man page:

fetch.recurseSubmodules

This option can be either set to a boolean value or to on-demand.

  • Setting it to a boolean changes the behavior of fetch and pull to unconditionally recurse into submodules when set to true or to not recurse at all when set to false.
  • When set to on-demand (the default value), fetch and pull will only recurse into a populated submodule when its superproject retrieves a commit that updates the submodule's reference.

The other alternative would be to ask them to do one more complex command:

git pull --recurse-submodules=on-demand

The git config setting mentioned above has the advantage to allow developers to do a simple git pull.

like image 83
VonC Avatar answered Sep 26 '22 01:09

VonC