1GITIGNORE(5)                      Git Manual                      GITIGNORE(5)
2
3
4

NAME

6       gitignore - Specifies intentionally untracked files to ignore
7

SYNOPSIS

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

DESCRIPTION

12       A gitignore file specifies intentionally untracked files that Git
13       should ignore. Files already tracked by Git are not affected; see the
14       NOTES below for details.
15
16       Each line in a gitignore file specifies a pattern. When deciding
17       whether to ignore a path, Git normally checks gitignore patterns from
18       multiple sources, with the following order of precedence, from highest
19       to lowest (within one level of precedence, the last matching pattern
20       decides the outcome):
21
22       ·   Patterns read from the command line for those commands that support
23           them.
24
25       ·   Patterns read from a .gitignore file in the same directory as the
26           path, or in any parent directory, with patterns in the higher level
27           files (up to the toplevel of the work tree) being overridden by
28           those in lower level files down to the directory containing the
29           file. These patterns match relative to the location of the
30           .gitignore file. A project normally includes such .gitignore files
31           in its repository, containing patterns for files generated as part
32           of the project build.
33
34       ·   Patterns read from $GIT_DIR/info/exclude.
35
36       ·   Patterns read from the file specified by the configuration variable
37           core.excludesFile.
38
39       Which file to place a pattern in depends on how the pattern is meant to
40       be used.
41
42       ·   Patterns which should be version-controlled and distributed to
43           other repositories via clone (i.e., files that all developers will
44           want to ignore) should go into a .gitignore file.
45
46       ·   Patterns which are specific to a particular repository but which do
47           not need to be shared with other related repositories (e.g.,
48           auxiliary files that live inside the repository but are specific to
49           one user’s workflow) should go into the $GIT_DIR/info/exclude file.
50
51       ·   Patterns which a user wants Git to ignore in all situations (e.g.,
52           backup or temporary files generated by the user’s editor of choice)
53           generally go into a file specified by core.excludesFile in the
54           user’s ~/.gitconfig. Its default value is
55           $XDG_CONFIG_HOME/git/ignore. If $XDG_CONFIG_HOME is either not set
56           or empty, $HOME/.config/git/ignore is used instead.
57
58       The underlying Git plumbing tools, such as git ls-files and git
59       read-tree, read gitignore patterns specified by command-line options,
60       or from files specified by command-line options. Higher-level Git
61       tools, such as git status and git add, use patterns from the sources
62       specified above.
63

PATTERN FORMAT

65       ·   A blank line matches no files, so it can serve as a separator for
66           readability.
67
68       ·   A line starting with # serves as a comment. Put a backslash ("\")
69           in front of the first hash for patterns that begin with a hash.
70
71       ·   Trailing spaces are ignored unless they are quoted with backslash
72           ("\").
73
74       ·   An optional prefix "!" which negates the pattern; any matching file
75           excluded by a previous pattern will become included again. It is
76           not possible to re-include a file if a parent directory of that
77           file is excluded. Git doesn’t list excluded directories for
78           performance reasons, so any patterns on contained files have no
79           effect, no matter where they are defined. Put a backslash ("\") in
80           front of the first "!" for patterns that begin with a literal "!",
81           for example, "\!important!.txt".
82
83       ·   If the pattern ends with a slash, it is removed for the purpose of
84           the following description, but it would only find a match with a
85           directory. In other words, foo/ will match a directory foo and
86           paths underneath it, but will not match a regular file or a
87           symbolic link foo (this is consistent with the way how pathspec
88           works in general in Git).
89
90       ·   If the pattern does not contain a slash /, Git treats it as a shell
91           glob pattern and checks for a match against the pathname relative
92           to the location of the .gitignore file (relative to the toplevel of
93           the work tree if not from a .gitignore file).
94
95       ·   Otherwise, Git treats the pattern as a shell glob: "*" matches
96           anything except "/", "?" matches any one character except "/" and
97           "[]" matches one character in a selected range. See fnmatch(3) and
98           the FNM_PATHNAME flag for a more detailed description.
99
100       ·   A leading slash matches the beginning of the pathname. For example,
101           "/*.c" matches "cat-file.c" but not "mozilla-sha1/sha1.c".
102
103       Two consecutive asterisks ("**") in patterns matched against full
104       pathname may have special meaning:
105
106       ·   A leading "**" followed by a slash means match in all directories.
107           For example, "**/foo" matches file or directory "foo" anywhere, the
108           same as pattern "foo". "**/foo/bar" matches file or directory "bar"
109           anywhere that is directly under directory "foo".
110
111       ·   A trailing "/**" matches everything inside. For example, "abc/**"
112           matches all files inside directory "abc", relative to the location
113           of the .gitignore file, with infinite depth.
114
115       ·   A slash followed by two consecutive asterisks then a slash matches
116           zero or more directories. For example, "a/**/b" matches "a/b",
117           "a/x/b", "a/x/y/b" and so on.
118
119       ·   Other consecutive asterisks are considered invalid.
120

NOTES

122       The purpose of gitignore files is to ensure that certain files not
123       tracked by Git remain untracked.
124
125       To stop tracking a file that is currently tracked, use git rm --cached.
126

EXAMPLES

128               $ git status
129               [...]
130               # Untracked files:
131               [...]
132               #       Documentation/foo.html
133               #       Documentation/gitignore.html
134               #       file.o
135               #       lib.a
136               #       src/internal.o
137               [...]
138               $ cat .git/info/exclude
139               # ignore objects and archives, anywhere in the tree.
140               *.[oa]
141               $ cat Documentation/.gitignore
142               # ignore generated html files,
143               *.html
144               # except foo.html which is maintained by hand
145               !foo.html
146               $ git status
147               [...]
148               # Untracked files:
149               [...]
150               #       Documentation/foo.html
151               [...]
152
153
154       Another example:
155
156               $ cat .gitignore
157               vmlinux*
158               $ ls arch/foo/kernel/vm*
159               arch/foo/kernel/vmlinux.lds.S
160               $ echo '!/vmlinux*' >arch/foo/kernel/.gitignore
161
162
163       The second .gitignore prevents Git from ignoring
164       arch/foo/kernel/vmlinux.lds.S.
165
166       Example to exclude everything except a specific directory foo/bar (note
167       the /* - without the slash, the wildcard would also exclude everything
168       within foo/bar):
169
170               $ cat .gitignore
171               # exclude everything except directory foo/bar
172               /*
173               !/foo
174               /foo/*
175               !/foo/bar
176
177

SEE ALSO

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

GIT

182       Part of the git(1) suite
183
184
185
186Git 2.18.1                        05/14/2019                      GITIGNORE(5)
Impressum