gitignore man page

gitignore — Specifies intentionally untracked files to ignore


$HOME/.config/git/ignore, $GIT_DIR/info/exclude, .gitignore


A gitignore file specifies intentionally untracked files that Git should ignore. Files already tracked by Git are not affected; see the Notes below for details.

Each line in a gitignore file specifies a pattern. When deciding whether to ignore a path, Git normally checks gitignore patterns from multiple sources, with the following order of precedence, from highest to lowest (within one level of precedence, the last matching pattern decides the outcome):

Which file to place a pattern in depends on how the pattern is meant to be used.

The underlying Git plumbing tools, such as git ls-files and git read-tree, read gitignore patterns specified by command-line options, or from files specified by command-line options. Higher-level Git tools, such as git status and git add, use patterns from the sources specified above.

Pattern Format

Two consecutive asterisks ("**") in patterns matched against full pathname may have special meaning:


The purpose of gitignore files is to ensure that certain files not tracked by Git remain untracked.

To stop tracking a file that is currently tracked, use git rm --cached.


$ git status
# Untracked files:
#       Documentation/foo.html
#       Documentation/gitignore.html
#       file.o
#       lib.a
#       src/internal.o
$ cat .git/info/exclude
# ignore objects and archives, anywhere in the tree.
$ cat Documentation/.gitignore
# ignore generated html files,
# except foo.html which is maintained by hand
$ git status
# Untracked files:
#       Documentation/foo.html

Another example:

$ cat .gitignore
$ ls arch/foo/kernel/vm*
$ echo '!/vmlinux*' >arch/foo/kernel/.gitignore

The second .gitignore prevents Git from ignoring arch/foo/kernel/vmlinux.lds.S.

Example to exclude everything except a specific directory foo/bar (note the /* - without the slash, the wildcard would also exclude everything within foo/bar):

$ cat .gitignore
# exclude everything except directory foo/bar

See Also

git-rm(1), gitrepository-layout(5), git-check-ignore(1)


Part of the git(1) suite

Referenced By

git-add(1), gitattributes(5), git-check-ignore(1), git-clean(1), git-commit(1), git-commit-tree(1), git-config(1), git-init(1), git-log(1), git-ls-files(1), git-read-tree(1), gitrepository-layout(5), git-show(1), git-status(1).

Explore man page connections for gitignore(5).