gitignore - Man Page

Specifies intentionally untracked files to ignore

Synopsis

$XDG_CONFIG_HOME/git/ignore, $GIT_COMMON_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 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:

Configuration

The optional configuration variable core​.excludesFile indicates a path to a file containing patterns of file names to exclude, similar to $GIT_COMMON_DIR/info/exclude​. Patterns in the exclude file are used in addition to those in $GIT_COMMON_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

    $ 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​.
    *​.[oa]
    $ cat Documentation/​.gitignore
    # ignore generated html files,
    *​.html
    # except foo​.html which is maintained by hand
    !foo​.html
    $ git status
    [​.​.​.]
    # Untracked files:
    [​.​.​.]
    #       Documentation/foo​.html
    [​.​.​.]

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 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
    /*
    !/foo
    /foo/*
    !/foo/bar

See Also

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

Git

Part of the git(1) suite

Info

11/10/2026 Git 2.56.1 Git Manual