According to the man page, there are three ways to exclude files from being tracked by git.

Shared list of files to ignore

The most well-known way of preventing files from being part of a git branch is to add such files in .gitignore. (This is analogous to CVS' .cvsignore files.)

Here's an example:

*.generated.html  
/config.php

The above ignore list will prevent automatically generated HTML files from being committed by mistake to the repository. Because this is useful to all developers on the project, .gitignore is a good place for this.

The next line prevents the local configuration file from being tracked by git, something else that all developers will want to have.

One thing to note here is the use of a leading slash character with config.php. This is to specifically match the config file in the same directory as the .gitignore file (in this case, the root directory of the repository) but no other. Without this slash, the following files would also be ignored by git:

/app/config.php  
/plugins/address/config.php  
/module/config.php

Local list (specific to one project)

For those custom files that you don't want version controlled but that others probably don't have or don't want to automatically ignore, git provides a second facility: .git/info/exclude

It works the same way as .gitignore but be aware that this list is only stored locally and only applies to the repository in which it lives.

(I can't think of a good example for when you'd want to use this one because I don't really use it. Feel free to leave a comment if you do use it though, I'm curious to know what others do with it.)

Local list (common to all projects)

Should you wish to automatically ignore file patterns in all of your projects, you will need to use the third gitignore method: core.excludesfile

Put this line in your ~/.gitconfig:

[core]  
excludesfile = /home/username/.gitexcludes

(you need to put the absolute path to your home directory, ~/ will not work here unless you use git 1.6.6 or later)

and then put the patterns to ignore in ~/.gitexcludes. For example, this will ignore the automatic backups made by emacs when you save a file:

*~

This is the ideal place to put anything that is generated by your development tools and that doesn't need to appear in your project repositories.

For your information, with Git 1.6.6 (released 2009-12-24) tilde expansion (~/) works in the config file.
Comment by Oz
I use .git/info/exclude to ignore the conf.vars file and the debian directory generated by make-kpkg.
Comment by Matt Kraai
The .git/info/exclude file is useful in e.g. git-svn repos, in which you don't want a racked .gitignore file, because the next dcommit would send that file to the svn repo, which would be quite weird ;-)
Comment by Björn Steinbrink
I guess if you're using VPATH builds in your git export, using .git/info/exclude could be useful...
Comment by wo

cool.

I will use .git/info/exclude to ignore my test.c file. It always has sample code I use to test "smatch" the static checker I'm developing.

-error27

Comment by Anonymous
I use it to ignore eclipse configuration files. Since the project owner uses a different configuration then I use on eclipse globally, I need to edit the project's config to match his global settings.
Comment by Oldarney