Ignoring files with Git
Published by marco on
Just to recap, here are the ways to ignore a file:
.gitignore: you can designate basic exclusion directives that apply to all repositories on your system. This file is not committed to any repository or shared with others. Execute
git config –global core.excludesfile ~/.gitignore_globalto set the file to
~/.gitignore_global(for example). See the linked article for sample directives.
- Per-repository global exclusions: add directives to the
.git/info/excludefile in any repository. These directives are combined with any system-global directives to form the base exclusions for that repository. This file is not committed with the repository. This is the one I’d never heard of before.
.gitignore: add a file with this name to any directory. The directives in that file are merged with those from the parent directory to define the patterns that are excluded in that directory and all child directories. This is definitely the most common way to exclude files.
- Exclude versioned files: and, finally, if your repository has files that are changed but not committed (e.g. configuration files), you can ignore future changes to those files with a call to
git update-index –assume-unchanged path/to/file.txt. While this can be useful for legacy projects, it’s best to structure new projects so developers don’t have to rely on easily forgotten tricks like this.