overview
gitignore files specify intentional untracked files that Git should ignore.
order of precedence
- Patterns from the command line
- Patterns from
.gitignorefile in same directory - Patterns from
.gitignorefile 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:**/foomatches a file or directory namedfooanywhere (the saame as the patternfoo)**/foo/barmatches file or directorybaranywhere directly under directoryfooa/**/bmatches 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> --cachedto remove the file from the index- Add the pattern to
.gitignore