How can I Remove .DS_Store files from a Git repository?

John Topley picture John Topley · Sep 20, 2008 · Viewed 657.5k times · Source

How can I remove those annoying Mac OS X .DS_Store files from a Git repository?

Answer

benzado picture benzado · Sep 20, 2008

Remove existing files from the repository:

find . -name .DS_Store -print0 | xargs -0 git rm -f --ignore-unmatch

Add the line

.DS_Store

to the file .gitignore, which can be found at the top level of your repository (or created if it isn't there already). You can do this easily with this command in the top directory

echo .DS_Store >> .gitignore

Then

git add .gitignore
git commit -m '.DS_Store banished!'