Skip to content

Instantly share code, notes, and snippets.

@facelordgists
Created May 13, 2015 05:28
Show Gist options
  • Save facelordgists/80e868ff5e315878ecd6 to your computer and use it in GitHub Desktop.
Save facelordgists/80e868ff5e315878ecd6 to your computer and use it in GitHub Desktop.
Recursively remove .git folders
( find . -type d -name ".git" && find . -name ".gitignore" && find . -name ".gitmodules" ) | xargs rm -rf
@mikeschinkel
Copy link

Nice! Thanks.

@iamburitto
Copy link

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

@cjohnson496
Copy link

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

@Shelob9
Copy link

Shelob9 commented Sep 18, 2018

Thanks. I added .gitattributes
`( find . -type d -name ".git" && find . -name ".gitignore" && find . -name ".gitmodules" && find . -name ".gitattributes" ) | xargs rm -rf

@luckman212
Copy link

I see a couple of problems here.

  1. 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.

  2. 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 -- {} +

@JasinYip
Copy link

Great! Thank you!

@pihamchi
Copy link

smart guys!

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