How to Remove .DS_Store files from a Git repository?

DS_Store files are automatically created by Mac OS X Finder in browsed directories. These files contain information about system configuration. If you upload them along with other files, the files can be misused to obtain information about your computer. For more information, see Apple security updates.

Sometimes it is annoying to see .DS_Store files added to your git repositories. Every time you do git status you may suddenly find new .DS_Store file in your git repository tree. So how to remove these git .DS_Store files and make your git repo not track them?

How to Remove .DS_Store files from a Git repository

How to remove DS_Store files from tracking

First of all, lets remove existing DS_Store files from the repository:

Next, add the following line to your .gitignore file, which can be found at the top level of your repository. (Or create the file if it isn’t there already):

You can do this easily with this command in the top directory:

Then commit the file to the repo:

Leave a Reply