Removing .DS_Store files from Git

Image for post
Image for post

There is nothing more frustrating to a developer than looking at their brand new repository, pushed with a fresh new project. Then you see one. Then two…three…more!

Those pesky .DS_Store files start popping up everywhere, and you realize you forgot to add them to your .gitignore file. Let me show you a quick command you can run to clear them out.

Run this command to find all instances of .DS_Store files in your repository and in your git history.

The next thing you’ll want to do is add .DS_Store to your .gitignore file immediately. That will protect you from yourself and other developers who work on MacOS.

Never Have This Happen Again

Wouldn’t it be nice if you forgot to add .gitignore to your .gitignore file in the future, that you would still be protected? You can protected yourself against this by creating a global gitignore file.

Add a .gitignore_global file to your Home Directory by running this command.

Now open that file in your favorite text editor and put in some common file patterns that you’ll most likely want to remain out of your Git history.

Originally published at on February 14, 2020.

Programmer and Business owner from Canada / USA. I help businesses and entrepreneurs develop amazing digital products 🚀

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store