Overview
gitignore files specify intentional untracked files that Git should ignore.
Order of Precedence
- Patterns from the command line
- Patterns from
.gitignore
file in same directory - Patterns from
.gitignore
file in parent directories up to the top level of the working tree - Patterns from
$GIT_DIR/info/exclude
- Patterns from the file specified by
core.excludesFile
Pattern Format
#
for comments\
for escapes/
as the directory separator char/
at the end of a pattern matches directories only
!
to negate the pattern; any matching file excluded by the previous pattern will be included again- Unless the parent directory of that file is excluded
*
matches anything except/
**
followed by/
means match all directories:**/foo
matches a file or directory namedfoo
anywhere (the saame as the patternfoo
)**/foo/bar
matches file or directorybar
anywhere directly under directoryfoo
a/**/b
matches a/b, a/x/b, a/x/y/b, and so on.
?
matches any one character except/
- Range notation
[a-zA-Z]
can be used to match one of the characters in the range
- Range notation
Trailing spaces are ignored (unless escaped)
Ignoring Files
If the file is currently tracked:
git rm <glob> --cached
to remove the file from the index- Add the pattern to
.gitignore