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'
Here's an example:
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:
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
[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.