Skip to content

Git: ignore Mac OSX icon files

When using git on Mac OSX and your project’s folder has a custom icon, you will see a “Iconr” File showing up in your git status or Source Tree. Ignoring this file doesn’t work.

The solution is to ignore the correct way (or syntax), because Apple uses ^M at the end of the filename, which is a CRLF, a hidden character. In fact you have to ignore “Icon^M^M” in your .gitignore file, but it’s not easy to enter these special characters as ^M is in fact one single CRLF character.

I found a hint using the ruby interactive interpreter, but i wanted to use my beloved Python, so here’s the code:

>>> f = open('.gitignore','a')
>>> f.write('Icon\r\r')
>>> f.close()

use this in your home directory as you need to edit ~/.gitignore and ~/.gitignore_global (for Source Tree)

1 thought on “Git: ignore Mac OSX icon files”

  1. Take it one step further place a .gitignore’ file wihitn a directory (example: images/useruploads) and ignore the directory EXCEPT for the .gitignore placed wihitn that directory. This way, when someone pulls your repo, it will create the directory for them but not include all of the files along side.The idea is, there must be at least one file wihitn the directory in order for GIT to create the directory.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.