Created
October 5, 2015 14:36
-
-
Save darrenclark/8492bd81aa2a6c8ccb14 to your computer and use it in GitHub Desktop.
Update submodules on branch switch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updates your submodules when switching branches.
To use, put in your repo at:
.git/hooks/post-checkout
& make it executable