Git

gitignore .DS_Store

If you are currently using or performing your development operations on a macOS operating system, you should be aware of .DS_Store files.

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.

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

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.

$ echo .DS_Store >> .gitignore

Finally, update your repo:

$ git add .
$ 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
$ 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.

About the author

John Otieno

My name is John and am a fellow geek like you. I am passionate about all things computers from Hardware, Operating systems to Programming. My dream is to share my knowledge with the world and help out fellow geeks. Follow my content by subscribing to LinuxHint mailing list