gitignore(5) (original) (raw)

SYNOPSIS

XDGCONFIGHOME/git/ignore,XDG_CONFIG_HOME/git/ignore, XDGCONFIGHOME/git/ignore,GIT_DIR/info/exclude, .gitignore

DESCRIPTION

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 checksgitignore 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, readgitignore 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:

CONFIGURATION

The optional configuration variable core.excludesFile indicates a path to a file containing patterns of file names to exclude, similar to$GIT_DIR/info/exclude. Patterns in the exclude file are used in addition to those in $GIT_DIR/info/exclude.

NOTES

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_ to remove the file from the index. The filename can then be added to the .gitignore file to stop the file from being reintroduced in later commits.

Git does not follow symbolic links when accessing a .gitignore file in the working tree. This keeps behavior consistent when the file is accessed from the index or a tree versus from the filesystem.

EXAMPLES

Another example:

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

The second .gitignore prevents Git from ignoringarch/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
/*
!/foo
/foo/*
!/foo/bar

SEE ALSO

GIT