Last active
September 15, 2024 14:44
-
-
Save brghena/fc4483a2df83c47660a5 to your computer and use it in GitHub Desktop.
Sensible git submodules
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
# 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 | |
} |
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
Add this code to your .bashrc file to automatically handle git submodules