Skip to content

Instantly share code, notes, and snippets.

@brghena
Last active December 16, 2020 16:04
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brghena/fc4483a2df83c47660a5 to your computer and use it in GitHub Desktop.
Save brghena/fc4483a2df83c47660a5 to your computer and use it in GitHub Desktop.
Sensible git submodules
# make git submodules usable
# This overwrites the 'git' command with modifications where necessary, and
# calls the original otherwise
git() {
if [[ $@ == clone* ]]; then
gitargs=$(echo "$@" | cut -c6-)
command git clone --recursive $gitargs
elif [[ $@ == pull* ]]; then
command git "$@" && git submodule update --init --recursive
elif [[ $@ == checkout* ]]; then
command git "$@" && git submodule update --init --recursive
else
command git "$@"
fi
}
@brghena
Copy link
Author

brghena commented Aug 21, 2015

Add this code to your .bashrc file to automatically handle git submodules

@bpkempke
Copy link

This has unintended behavior if you're trying to just revert working copy modifications to a single file e.g.

git checkout -- dw1000.c

This proceeds to revert any commits in submodules which haven't been committed to the parent repository. Any ideas on how to fix this behavior?

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