Removing .DS_Store Files from Git Repositories
If you are a Mac user who also uses Git, you might accidentally commit a .DS_Store
file. This could confuse your Windows colleagues, who may wonder what these files do and why you’ve committed them.
First, what is a .DS_Store
file? 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 store custom attributes like the positions of icons. These files are created and maintained by the Finder application on a Mac, and are normally hidden.
These .DS_Store
files are not useful to Windows users and do not need to be committed to your GitHub repository. To remove existing .DS_Store
files from your repository, run the following command:
find . -name .DS_Store -print0 | xargs -0 git rm -f --ignore-unmatch
Afterwards, commit the changes to remove those files and push to the remote repository. To prevent these files from being added again, edit your .gitignore file and add the following line:
.DS_Store
Doing so will address any concerns your colleagues may have.