Removing .DS_Store files from an existing GitHub repository

I use GitHub extensively to host my projects. I interact with Git using GitHub’s free GitHub Desktop app.

I have a repo that I forgot to exclude .DS_Store files in at the start. Now, no matter what I do, I can’t get rid of them all.

Does anyone know the git voodoo to purge these and stop tracking them?

in terminal go to the repository root directory.
then execute this command:

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

in your .gitignore add “.DS_Store” and “**/.DS_Store” each on it’s own line.

Commit, and you are good to go.
this only works as-is if you have those hidden .DS_Store files in the repository already.
Otherwise just adding to the .gitignore would do the trick, so next time first add the .gitignore with those lines.

4 Likes

Add .DS_Store to gitignore
Delete all .DS_Store files
Commit the deletes and the gitignore

FWIW, there is a default gitignore for Xojo. When you create a new repository on Github, select “Xojo” as the language and you’ll get a handy ready-to-go .gitignore.

To use that template for anything you have already existing, you can find it here: gitignore/Xojo.gitignore at main · github/gitignore · GitHub

Edit: And today I learned .DS_Store is not in that template hah. Foot. in. mouth.
Edit 2: I’ve made a pull request with a gitignore template that includes the Xojo things and .DS_Store for you :slight_smile:

7 Likes

Q. When .DS_Store files are created ?
A. Usually, when I open a folder, not when I create it.
(it may be after I move the opened folder or resize the opened folder, but one need to open the folder).

So, if you copy files in a fresh Folder and share that folder without opening it, you’re ok: no .DS_Store will exist in that folder.

Knowing your ennemi often help.

Thank you @DerkJ and @Tim_Parnell - problem sorted.

Super helpful as always.

2 Likes