git how to: ignoring files in git

Sharad Jain

This post was previously on the Pathfinder Software site. Pathfinder Software changed its name to Orthogonal in 2016. Read more.

Just as we moved from cvs to subversion to git, our ignore files changed from .cvsignore to .svnignore to .gitignore. However, git offers more flexibility in managing our ignore files depending on the situation you are in. Here are a few options, I’ve found:

Directory-specific ignores (.gitignore):

This is the most common scenario for ignoring files in a specific directory. This file is also almost always checked into version-control to share with other developers.

Repository-wide ignores (.git/info/exclude):

This resides inside .git/ directory and is not shared with other developers. Such a file would be useful if I want to keep a few files local to my development environment. For example, this allows me to keep my nbproject/ folder (netbeans folder) out of repository which I don’t want to share with other developers.

Global ignores (~/.gitignore):

This doesn’t work by default. To enable this, you would need to set following global git config:

git config --global core.excludesfile ~/.gitignore

Once the above global config is set, any ignore patterns added to this file will be ignored for all your git projects. I’ve found that most stuff that I used to add to repository-specific ignore files could go here, once and for all 🙂

I am left with one question though: How do I ignore a file that already exists in codebase?

Why do I need that? you ask. I need it for files like config/database.yml which are already in the database but I need a slightly modified version of it for myself. I know, I know, we can agree as a team to have config/database.yml.template only in the database. But, what if I didn’t have that option?

Related Posts


Roundup: Bluetooth Medical Devices Cleared by FDA in 2023

White Paper

Software as a Medical Device (SaMD): What It Is & Why It Matters


SaMD Cleared by the FDA: The Ultimate Running List


Help Us Build an Authoritative List of SaMD Cleared by the FDA