Created
May 13, 2015 05:28
-
-
Save facelordgists/80e868ff5e315878ecd6 to your computer and use it in GitHub Desktop.
Recursively remove .git folders
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
( find . -type d -name ".git" && find . -name ".gitignore" && find . -name ".gitmodules" ) | xargs rm -rf |
If you want this to work with file & directory names that have whitespace in them you can change the delimiter to '\n':
( find . -type d -name ".git" && find . -name ".gitignore" && find . -name ".gitmodules" ) | xargs -d '\n' rm -rf
Since MacOS High Sierra 10.13+ has an installed xargs that doesn't support the -d
argument, you can use -0
in its place.
( find . -type d -name ".git" && find . -name ".gitignore" && find . -name ".gitmodules" ) | xargs -0 rm -rf
Thanks. I added .gitattributes
`( find . -type d -name ".git" && find . -name ".gitignore" && find . -name ".gitmodules" && find . -name ".gitattributes" ) | xargs rm -rf
I see a couple of problems here.
-
Separating the
find
commands with&&
means that the subsequent ones will only run if the last one had an exitcode == 0. That might not always be the case. -
Lots of forking (
find
->find
->find
->find
->xargs
). That could be simplified and done without any pipes:
find . \( -name ".git" -o -name ".gitignore" -o -name ".gitmodules" -o -name ".gitattributes" \) -exec rm -rf -- {} +
Great! Thank you!
smart guys!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice! Thanks.