Created
April 23, 2014 13:00
-
Star
(456)
You must be signed in to star a gist -
Fork
(84)
You must be signed in to fork a gist
-
-
Save nicktoumpelis/11214362 to your computer and use it in GitHub Desktop.
Cleans and resets a git repo and its 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
git clean -xfd | |
git submodule foreach --recursive git clean -xfd | |
git reset --hard | |
git submodule foreach --recursive git reset --hard | |
git submodule update --init --recursive |
git restore . --recurse-submodules
It resets the submodules back
Does it also take care of the git reset --hard --recurse-submodules
to discard any changes in the working trees? If so, why do the git restore
last and not first?
The key for me was git submodule sync
. Thank you @larsbrinkhoff @yuzhichang!
It's a sneaky issue whenever the URLs specified in .gitmodules
get updated, but the old URLs continue to silently be used (as shown by git submodule foreach --recursive git remote get-url origin
). Git should honestly warn us whenever the two are different.
Maybe
git submodule sync
?
For anyone coming new to all these commands, I believe this suggestion is 'as well', not 'instead' (see later comments for what this adds).
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It resets the submodules back