Get rid of annoying .DS_Store files in all your Git repositories

Tags:

Don’t you love it when every Git project you start on your Mac needs a .gitignore file before anything else, because the .DS_Store files are spawning and haunting your machine like a wandering ghost from the past? 👻

The solution: Global .gitignore

You can configure Git to globally ignore certain files across all repositories on your system. To do this, you can set up a global .gitignore file. This file will contain patterns for files or directories that you want Git to ignore across all your projects.

Here’s how you can create a global .gitignore file and ignore .DS_Store files:

Open your terminal and create a global .gitignore file.

touch ~/.gitignore_global

Open the global .gitignore file in a text editor of your choice. You can use a command-line text editor like nano or vim, or use a graphical text editor such as TextEdit or the wonderful Plain Text Editor.

nano ~/.gitignore_global

Add the following line to the file to ignore .DS_Store files:

.DS_Store

Save and exit the editor. Now, configure Git to use the global .gitignore file:

git config --global core.excludesfile ~/.gitignore_global

That’s it!

From now on, Git will ignore any file or directory specified in your global .gitignore file across all your repositories. Make sure that you don’t have local .gitignore files in your repositories that conflict with the global one.

Portrait of Moritz Glantz

👋 Moritz Glantz is my name…

…and I am an Specialist for Web Accessibility and UX-Engineer with over 20 years of experience, by day and a podcaster by night.

I help organizations build accessible websites by offering talks about accessibility, workshops & trainings, accessibility reviews and developing strategies for developers and management.

If that sounds like you could use my help, let’s talk! 💬