How to force Git to ignore files 24 May, 2008

Just documenting this one for later, really. If you’re setting up a git repository and you need to ignore certain types of file - logs, or python bytecode (not that I’m dealing with those two problems at this exact moment or anything), the procedure is quite simple:

# Get to the hidden .git directory within your project.
cd /path/to/your/project
cd .git/info
# in .git/info is a file named "exclude". Open it in whatever you like. Here we'll open it with Textmate.
mate exclude
The file’s contents are, by default, commented out. To add your own ignore rules, just add each rule on a new line. Here’s a simple example from a Python project which prevents bytecode and Textmate project files from being committed:

*.pyc
*.tmproj
In a Rails project, you’d likely want a set of rules like the following completely untested fragment:

log
*.log
*.pid
tmp
Photo of Dan speaking at an event

Dan Glegg is a software developer living and working in Brighton, United Kingdom. He works mainly with Ruby, Objective-C, Flex and W3C standards and spends most of his time developing products, often with startup companies.

Blog comments powered by Disqus