Skip to content

Instantly share code, notes, and snippets.

@polmuz
Last active December 14, 2015 04:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save polmuz/5030959 to your computer and use it in GitHub Desktop.
Save polmuz/5030959 to your computer and use it in GitHub Desktop.
Update submodules automatically after checkout when HEAD changes
Update submodules automatically after checkout
----------------------------------------------
Put the file post-checkout in .git/hooks/
Make it executable
(chmod u+x .git/hooks/post-checkout)
Never update your submodules manually again (unless something goes horribly wrong)!
#!/bin/sh
# Third parameter of post-checkout hook is 1 if the branch changed and
# it's 0 if the chechout was to restore the state of a file. We only
# want to update the submodules when the HEAD changes.
HEAD_CHANGED=$3
if [ $HEAD_CHANGED = "1" ]
then
echo "Updating Submodules ============="
git submodule update --init --recursive
echo "Subodules updated ==============="
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment