July 29, 2018

106 words 1 min read

Remove All git Files From a Directory Recursively

Remove All git Files From a Directory Recursively

The .git folder is tipically stored in the root directory of the repository, not all the sub-directories like Subversion did.

We can simply delete that .git folder, unless We are having Submodules, in this case We need to look for each submodules folder to remove it.

There’s a handy script to remove those .git folders simultaneously using bash command:

# 1. Go to your directory
$ cd /to/your/directory

# 2. Find all git related files recursively and remove all
$ ( find . -type d -name ".git" \
  && find . -name ".gitignore" \
  && find . -name ".gitmodules" ) | xargs rm -rf 

Credits: https://stackoverflow.com/questions/4822321