Skip to content

Instantly share code, notes, and snippets.

@darrenclark
Created October 5, 2015 14:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save darrenclark/8492bd81aa2a6c8ccb14 to your computer and use it in GitHub Desktop.
Save darrenclark/8492bd81aa2a6c8ccb14 to your computer and use it in GitHub Desktop.
Update submodules on branch switch
#!/bin/sh
# 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
fi
git submodule update --init --recursive
fi
@darrenclark
Copy link
Author

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