This article originally appeared on earthli News and has been cross-posted here.
The helpful page, Ignoring files, taught me something I didn't know: there's a file you can use to ignore files in your local Git repository without changing anyone else's repository.
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.
.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.
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.
Sign up for our Newsletter