DS_Store files refer to Desktop Service Store files. They are a set of files created automatically when a folder is opened in the macOS Finder application. They hold attribute and metadata information such as folder view options and icon formatting of their respective folders.
Think of it as the hidden desktop.ini file if you have ever used Windows.
Although .DS_Store files are hidden in the macOS operating system. They can still be ported into a repository without the user knowing.
This short tutorial will discuss how you can remove these files from a repository and prevent git from tracking them.
Remove DS_Store From Git Repo
If you already have DS_Store files committed in a repository, you must first remove them using the git rm command.
The command below will allow you to locate all the DS_Store files in the repo and remove them.
The command above uses the find command to recursively search for .DS_Store files in all the folders in the repository.
The find command should then return the path to the.DS_Store file.
We then take the output from the command and pipe it to xargs and the git rm command. This allows us to remove all the DS_Store files in that repository.
Once you have removed the files from your repo, exclude them from git tracking by adding them to the gitignore file.
Finally, update your repo:
$ git commit -m "Remove .DS_Store Files."
You can also ignore them by adding a global configuration. Run the command:
$ echo "**/.DS_Store" >> ~/.gitignore_global
$ git config --global core.excludefile ~/.gitignore_global
Conclusion
This short tutorial provides instructions on how to remove .DS_Store files from your git repo.