Questions tagged
gitignore
.gitignore is a file that lists files, directories, and/or path patterns that Git should not include as part of a repository.

.gitignore is a file that lists files that git should not include as part of a repository. It is typically used on binaries, temporary files, and packages.

For questions that are specific to Git's ignore mechanism, such as ignore-file syntax, use this tag. For VCS-agnostic questions, such as whether certain types of files should be checked into source control, use the ignore tag.

Gitignore grammar

.gitignore interprets direct filenames and wildcards (both of which are recursive, front and back),

file.name   # Will match file.name, foo/file.name, foo/bar/file.name, etc.
*.tmp       # Will match out.tmp, foo/out.tmp, etc.
cache/*.bak # Will match cache/out.bak, foo/cache/out.bak, etc.

This recursive behavior can be stopped by adding a leading / to the line.

/file.name # Will only match toplevel file.name
/*.tmp     # Will only match toplevel tmp files
/cache/*.bak # Will only match bak files directly under cache

.gitignore will also do simple character classes.

foo.[abc] # foo.a, foo.b, and foo.c

It uses the # to denote comments.

# This comment goes until the end of the line

Certain files can also be excepted from wildcards by using the ! syntax.

# Ignore all *.config files except the default that ships
*.config
!default.config

It is imperative to note that gitignore uses the unix fnmatch style patterns to ignore files.

See the man page for more details.

To know which rule of which .gitignore is ignoring your file, use git check-ignore (since Git 1.8.3.3, July 2013):

git check-ignore -v -- path/to/your/file

Tools and examples