Skip to content

Instantly share code, notes, and snippets.

Created October 5, 2015 14:36
What would you like to do?
Update submodules on branch switch
# To skip submodule update:
# IGNORE_SUBMODULES=1 git checkout <...>
# Third arg is "1" when doing a branch checkout (as opposed to a file
# checkout)
if [ "$3" = "1" ] && [ -z "$IGNORE_SUBMODULES" ]; then
# Only sync submodules if .gitmodules has changed (`git submodule
# sync` can be a little slow)
should_sync="$(git diff --exit-code $1 $2 -- .gitmodules; echo $?)"
if [ "$should_sync" != "0" ]; then
git submodule sync --recursive
git submodule update --init --recursive
Copy link

Updates your submodules when switching branches.

To use, put in your repo at: .git/hooks/post-checkout & make it executable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment