How remove .DS_Store files from a Git repository?

[Thumbnail image]

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

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

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 where you can configure your own .gitignore file by few clicks.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.