git how to: ignoring files in git
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 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 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 exist in codebase?
Why do I need that?, you ask. I need it for files like config/database.yml which are already in 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 database. But, what if I didn't have that option?
Comments: 5 so far
Leave a comment
About Pathfinder
Follow the Blog
-
Get a monthly update on best practices for delivering successful software.
Subscribe via email
Subscribe via RSS
Categories
Topics
Archives
- July 2009
- June 2009
- May 2009
- April 2009
- March 2009
- February 2009
- January 2009
- December 2008
- November 2008
- October 2008
- September 2008
- August 2008
- July 2008
- June 2008
- May 2008
- April 2008
- March 2008
- February 2008
- January 2008
- December 2007
- November 2007
- October 2007
- September 2007
- August 2007
- July 2007
- June 2007
- May 2007
- April 2007
- March 2007
- February 2007
- January 2007
- December 2006
- November 2006
- October 2006
- September 2006
- August 2006
- July 2006
- June 2006
- May 2006
- April 2006
- March 2006
Blogroll
Recent
- Elements of Testing Style
- Aesthetics and Web Design
- Asterisk-Java Testing with Groovy
- 3 Misuses of Code Comments
- Fluently NHibernate
- Digging a Hole and Covering it with Leaves — The Software Development Version
- The Importance of User Experience - Do You Understand It in Your Bones?
- Writing Your Own Protocol With NSURLProtocol
- What’s In Your Dock: iPhone edition
- Feature Fatigue

I feel you pain. I’ve forked a number of libraries where compiled binaries have snuck into the repository. (Bundled Merb apps prior to 1.06 like merb-book are the worst offenders.) The developer who owns these file has no reason to remove them they don’t bother him, but I clobber them every time I redeploy. I then have to meticulously keep them out of my commits because binary changes almost always create merge conflicts. If you find a solution let me know!
Comment by Antares Trader, Friday, January 9, 2009 @ 8:06 pm
Thanks for this round-up; I only knew about the first two options.
Has anyone found .gitignore to be intermittent? I often find I need to remove a file from the repo, delete the entry in .gitignore, return the file to the repo, then add the entry back in to .gitignore - otherwise it just won’t include the file in the list of ignored files. Is this just me or has anyone else seen this?
Comment by Neil, Saturday, January 10, 2009 @ 2:36 am
You solve it by not having production configs in the repository and having Capistrano or whatever deployment system/script you use symlink database.yml to an immutable copy on the server.
That is the convention at least.
Thanks for your article. Git rocks and so does github.
Comment by Erik Petersen, Saturday, January 10, 2009 @ 9:55 am
You’ll need to do git rm –cached to keep the file in your tree and then ignore it.
From Here : http://www.gitready.com/beginner/2009/01/19/ignoring-files.html
Comment by greb, Sunday, April 26, 2009 @ 12:35 am
http://GitReady.com/ is a great resource: Thanks for stopping by and pointing out.
Comment by Sharad Jain, Tuesday, April 28, 2009 @ 10:53 am