Removing .DS_Store Files from Git Repositories

March 27, 2020

If you are a Mac user and also use Git, you might accidentally commit a .DS_Store file. This could leave your Windows colleagues puzzled about the purpose of these files and why you committed them.

Firstly, what is a .DS_Store file? The "DS" stands for Desktop Services, and these files are used by Macs to determine how to display folders when you open them. For example, they contain custom attributes, such as the positions of icons. These files are created and maintained by the Finder application on Macs, and are usually hidden from view.

These .DS_Store files are not useful to Windows users and do not need to be committed to your GitHub repository. To remove any existing .DS_Store files from the repository, run the following command:

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

After that, commit the changes to remove those files and push them to the remote repository. To prevent these files from being added again in the future, edit your .gitignore file and add the following line:

    .DS_Store

This should address any concerns your colleagues may have.


Profile picture

Software development professional with expertise in application architecture, cloud solutions deployment, and financial products development. Possess a Master's degree in Computer Science and an MBA in Finance. Highly skilled in AWS (Certified Solutions Architect, Developer and SysOps Administrator), GCP (Professional Cloud Architect), Microsoft Azure, Kubernetes(CKA, CKAD, CKS, KCNA), and Scrum(PSM, PSPO) methodologies. Happy to connect