Remove .DS_Store files in git

If you are a mac user and using git, you may accidentally commit a file with .DS_Store. Your windows colleague would be confused what does this files do and why do you commit it.

First of all, what is .DS_Store file? DS stands for Desktop Services, which are used for mac to work out how to display folders when you open them. Example of those custom attributes includes the position of icons. These are created and maintained by the Finder application in mac which you normally won’t notice these hidden files.

These files are not useful for windows users and you don’t need to commit them to Github repository. To remove existing files from the repository, you can run the below command:

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

After that, you may commit deleted those files and push to the remote repository. In order to prevent it from being added again, edit the .gitignore file and add this line:

.DS_Store

This would then resolve the concerns from your colleagues.


Originally published at https://victorleungtw.com.

By Victor Leung

Experience in software development, consulting services and technical product management. Understanding of business and technology with an MBA in Finance and a Master degree in Computer Science. AWS Certified Solution Architect with experience in building products from scratch and serving as a charismatic leader.

Leave a comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

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