Skip to main content

How remove .DS_Store files from a Git repository?

Mac OS X users can include system .DS_Store files to repository accidentally.

First, you can check how much .DS_Srore files you have on your work directory. Use fallow command:

find .* -name ".DS_Store" -type f

To remove all .DS_Store files from git you can use fallowing command:

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

Update .gitignore file # Anchor link

Add 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 "# Apple macOS\n.DS_Store\n.DS_Store?\n*/.DS_Store" >> .gitignore

Then add and commit your new .gitignore file

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

Avoid this issue in future # Anchor link

echo "# Apple macOS\n.DS_Store\n.DS_Store?\n*/.DS_Store" >> ~/.gitignore_global

Set the global git configuration

git config --global core.excludesfile ~/.gitignore_global

Admire your great work?

Also, check gitignore.io where you can configure your own .gitignore file by few clicks.

May the 4th be with you,
Alex