Using a Git Excludes File
Within a Git repository you can ignore files either by adding them to a .gitignore file, or by listing them in .git/info/excludes. The second option is useful for ignoring files which are particular to your copy of the repository. For example, I use Emacs for editing and often have two Emacs-related files in each of my repositories: .emacs.desktop and TAGS. I list these in .git/info/excludes to keep them out of the repository, but I do not include them in a .gitignore because other people probably will not have those files to begin with.
However, it gets old ignoring those files again and again, for each new repository. Fortunately Git provides a way of automating that. First you need to create a file that listes all the files you would like to ignore in each new repository. For me this file is /home/eric/.gitexcludes and it looks like this:
# Ignore Emacs files .emacs.desktop* TAGS # Ignore settings files for Django projects settings.py
Then tell Git where to find this file by setting the core.excludesfile config variable. You can either do this in your .gitconfig file, or you can set it from the command line by running
$ git config --global core.excludesfile path-to-your-excludes-file
Now any new repository you create or clone will automatically ignore everything your excludes file.
Related posts:
- Version Control Your Home Directory
- Commit Templates
- Working With Git
- Linux File Management
- Versioning Word Documents In Git

Leave a comment