Stop letting .DS_Store slow you down

I have over 100 git repositories on my Mac, and for almost every one, I sometimes browse the directory structure in the Finder. Once I do that, I inevitably end up with a few pesky .DS_Store files that want to be added to my repo:

Pesky .DS_Store Files in Terminal during Git Status

.DS_Store files don't add anything of value to my code (they just tell Mac OS X about folder display and icons), so I always end up adding them to my own projects' .gitignore files. But when I'm working on other repositories (like Drupal, or a fork from GitHub) I don't want to add a .gitignore if none exists, or mess with the project's existing .gitignore. So what's a coder to do?

There are a couple good solutions:

  1. Set git's core.excludesfile setting to a file of your choosing, with *.DS_Store inside:
    $ git config --global core.excludesfile ~/.gitignore
    $ echo *.DS_Store >> ~/.gitignore

    (Adapted from this SO answer.)
  2. You can avoid adding a .gitignore file on a per-repo basis by adding *.DS_Store to one repository's .git/info/exclude file (the .git folder is an invisible folder in the root of your git repo).

There! No more .DS_Store killing your commit momentum!

[Update: @applemachome told me about a for-pay app, BlueHarvest, that should help with this problem in a more general fashion (it can keep pesky .DS_Store files off of external and shared network volumes, too!). But it's probably overkill for most people.]


If you're using ZSH for terminal, using the following command does not work: echo *.DS_Store >> ~/.gitignore
Which outputs: zsh: no matches found: *.DS_Store

Instead use the following: echo '*.DS_Store' > ~/.gitignore