Remove .DS_Store files from Git

April 4, 2020
git macOS

Remove .DS_Store files from Git

It gets annoying when you see a .DS_Store file in every single directory after you push to a git repository. Luckily, we can use .gitignore to ignore them when you commit your changes. I found a pretty good solution on Stack Overflow:

Remove existing files from the repository:

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

Add the line

.DS_Store

to the file .gitignore, which can be found at the top level of your repository (or created if it isn’t there already). You can do this easily with this command in the top directory

echo .DS_Store >> .gitignore

Then

git add .gitignore
git commit -m '.DS_Store banished!'

This is mainly for easing my own headaches, but I would like to share to anyone who needs it as well.

Initialize Git with an existing project

April 8, 2020
git