I found myself contributing to an open source project recently … here & here. First thing that I thought awkward was that the project’s .gitignore file paid no attention to OS- generated or editor-generated files. So I happily contributed those exclusions to the project’s .gitignore so we ended up with this

# Editor Files #
*.komodoproject

# OS generated files #
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
Icon?
ehthumbs.db
Thumbs.db

Which isn’t elegant. At all.

I have a slight problem with this, though. The .DS_Store isn’t related to your project, it is related to the system you’re coding on. Your .gitignore file will be a lot more elegant if it only lists files that are related to the projects.

Solution

Git has a global configuration that applies rules to all of your projects.

On linux for example:

$ git config --global core.excludesfile ~/.global_ignore

On Windows (if using GitHub. for Windows) the .gitconfig file lives in the user’s home directory. In my case, for example ( & on Windows Vista/8), the location of the .gitconfig file is C:\Users\YOU\.gitconfig. To set up a global gitconfig, I use a directory C:\Users\YOU\config\ containing a file called global_ignore, and in .gitconfig I would add;

[user]
    name = King'ori Maina
    email = [email protected]

[core]
    excludesfile = C:/Users/itskingori/configs/global_ignore

And finally in the global_ignore file we have something like;

## Editor Files ##
*.sublime-project
*.sublime-workspace

## Backup ##
*.bak

## Logs and databases ##
*.log
*.sql
*.sqlite

## Packages ##
# it's better to unpack these files and commit the raw source
# git has its own built in compression methods
*.7z
*.dmg
*.gz
*.iso
*.jar
*.rar
*.tar
*.zip

# OS generated files #
$RECYCLE.BIN/
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
Desktop.ini
Icon?
ehthumbs.db
Thumbs.db

Of course this is my pref, feel free to use whatever suits you.


  1. A collection of useful .gitignore Templates
  2. Ignoring files
  3. Setting up a global .gitignore for Github for Windows
  4. Global gitignores