Exclude all .git or .svn folders from Spotlight index I would like to exclude all the .git and .svn folders on my hardrive from the Spotlight index. I know I can manually add them through the GUI but since they are many of them, and often new ones, it would be difficult.

Is there any way to exclude a folder by name (rather than full path)? Or is there any way to exclude the folders using the command line (in which case, I could automatically find them and exclude them from time to time)?
It is possible to exclude a folder using the command-line.

From there try this:


Open a Terminal window
Type 

sudo defaults write /.Spotlight-V100/VolumeConfiguration.plist Exclusions -array-add 'path/to/exclude'


So I guess you can try this using xargs' magic:

sudo locate .git | xargs -I {} defaults write /.Spotlight-V100/VolumeConfiguration.plist Exclusions -array-add  {}

You can check it worked using this:

sudo defaults read /.Spotlight-V100/VolumeConfiguration.plist Exclusions

You can remove all entries (there is no -array-remove option) using this:

sudo defaults write /.Spotlight-V100/VolumeConfiguration.plist Exclusions -array

Be careful with these commands, I don't know if there are side effects.

I could not really check this worked for my .git folders since none of them were displayed by spotlight search before nor after running these commands.