1 <?xml version="1.0" encoding="UTF-8"?>
\r
2 <!DOCTYPE sect2 SYSTEM "../../../dtd/dblite.dtd">
\r
4 <sect2 lang="en" id="gitignore(5)">
\r
5 <title>gitignore(5)</title>
\r
7 <primary>gitignore(5)</primary>
\r
9 <simplesect id="gitignore(5)__name">
\r
11 <simpara>gitignore - Specifies intentionally untracked files to ignore</simpara>
\r
13 <simplesect id="gitignore(5)__synopsis">
\r
14 <title>SYNOPSIS</title>
\r
15 <simpara>$XDG_CONFIG_HOME/git/ignore, $GIT_DIR/info/exclude, .gitignore</simpara>
\r
17 <simplesect id="gitignore(5)__description">
\r
18 <title>DESCRIPTION</title>
\r
19 <simpara>A <emphasis>gitignore</emphasis> file specifies intentionally untracked files that
\r
21 Files already tracked by Git are not affected; see the NOTES
\r
22 below for details.</simpara>
\r
23 <simpara>Each line in a <emphasis>gitignore</emphasis> file specifies a pattern.
\r
24 When deciding whether to ignore a path, Git normally checks
\r
25 <emphasis>gitignore</emphasis> patterns from multiple sources, with the following
\r
26 order of precedence, from highest to lowest (within one level of
\r
27 precedence, the last matching pattern decides the outcome):</simpara>
\r
31 Patterns read from the command line for those commands that support
\r
37 Patterns read from a <emphasis>.gitignore</emphasis> file in the same directory
\r
38 as the path, or in any parent directory, with patterns in the
\r
39 higher level files (up to the toplevel of the work tree) being overridden
\r
40 by those in lower level files down to the directory containing the file.
\r
41 These patterns match relative to the location of the
\r
42 <emphasis>.gitignore</emphasis> file. A project normally includes such
\r
43 <emphasis>.gitignore</emphasis> files in its repository, containing patterns for
\r
44 files generated as part of the project build.
\r
49 Patterns read from <emphasis>$GIT_DIR/info/exclude</emphasis>.
\r
54 Patterns read from the file specified by the configuration
\r
55 variable <emphasis>core.excludesFile</emphasis>.
\r
59 <simpara>Which file to place a pattern in depends on how the pattern is meant to
\r
64 Patterns which should be version-controlled and distributed to
\r
65 other repositories via clone (i.e., files that all developers will want
\r
66 to ignore) should go into a <emphasis>.gitignore</emphasis> file.
\r
72 specific to a particular repository but which do not need to be shared
\r
73 with other related repositories (e.g., auxiliary files that live inside
\r
74 the repository but are specific to one user's workflow) should go into
\r
75 the <emphasis>$GIT_DIR/info/exclude</emphasis> file.
\r
80 Patterns which a user wants Git to
\r
81 ignore in all situations (e.g., backup or temporary files generated by
\r
82 the user's editor of choice) generally go into a file specified by
\r
83 <emphasis>core.excludesFile</emphasis> in the user's <emphasis>~/.gitconfig</emphasis>. Its default value is
\r
84 $XDG_CONFIG_HOME/git/ignore. If $XDG_CONFIG_HOME is either not set or
\r
85 empty, $HOME/.config/git/ignore is used instead.
\r
89 <simpara>The underlying Git plumbing tools, such as
\r
90 <emphasis>git ls-files</emphasis> and <emphasis>git read-tree</emphasis>, read
\r
91 <emphasis>gitignore</emphasis> patterns specified by command-line options, or from
\r
92 files specified by command-line options. Higher-level Git
\r
93 tools, such as <emphasis>git status</emphasis> and <emphasis>git add</emphasis>,
\r
94 use patterns from the sources specified above.</simpara>
\r
96 <simplesect id="gitignore(5)__pattern_format">
\r
97 <title>PATTERN FORMAT</title>
\r
101 A blank line matches no files, so it can serve as a separator
\r
107 A line starting with # serves as a comment.
\r
108 Put a backslash ("<emphasis>\</emphasis>") in front of the first hash for patterns
\r
109 that begin with a hash.
\r
114 Trailing spaces are ignored unless they are quoted with backslash
\r
115 ("<emphasis>\</emphasis>").
\r
120 An optional prefix "<emphasis>!</emphasis>" which negates the pattern; any
\r
121 matching file excluded by a previous pattern will become
\r
122 included again. It is not possible to re-include a file if a parent
\r
123 directory of that file is excluded. Git doesn't list excluded
\r
124 directories for performance reasons, so any patterns on contained
\r
125 files have no effect, no matter where they are defined.
\r
126 Put a backslash ("<emphasis>\</emphasis>") in front of the first "<emphasis>!</emphasis>" for patterns
\r
127 that begin with a literal "<emphasis>!</emphasis>", for example, "<emphasis>\!important!.txt</emphasis>".
\r
132 The slash <emphasis>/</emphasis> is used as the directory separator. Separators may
\r
133 occur at the beginning, middle or end of the <emphasis>.gitignore</emphasis> search pattern.
\r
138 If there is a separator at the beginning or middle (or both) of the
\r
139 pattern, then the pattern is relative to the directory level of the
\r
140 particular <emphasis>.gitignore</emphasis> file itself. Otherwise the pattern may also
\r
141 match at any level below the <emphasis>.gitignore</emphasis> level.
\r
146 If there is a separator at the end of the pattern then the pattern
\r
147 will only match directories, otherwise the pattern can match both
\r
148 files and directories.
\r
153 For example, a pattern <emphasis>doc/frotz/</emphasis> matches <emphasis>doc/frotz</emphasis> directory,
\r
154 but not <emphasis>a/doc/frotz</emphasis> directory; however <emphasis>frotz/</emphasis> matches <emphasis>frotz</emphasis>
\r
155 and <emphasis>a/frotz</emphasis> that is a directory (all paths are relative from
\r
156 the <emphasis>.gitignore</emphasis> file).
\r
161 An asterisk "<emphasis>*</emphasis>" matches anything except a slash.
\r
162 The character "<emphasis>?</emphasis>" matches any one character except "<emphasis>/</emphasis>".
\r
163 The range notation, e.g. <emphasis>[a-zA-Z]</emphasis>, can be used to match
\r
164 one of the characters in a range. See fnmatch(3) and the
\r
165 FNM_PATHNAME flag for a more detailed description.
\r
169 <simpara>Two consecutive asterisks ("<emphasis>**</emphasis>") in patterns matched against
\r
170 full pathname may have special meaning:</simpara>
\r
174 A leading "<emphasis>**</emphasis>" followed by a slash means match in all
\r
175 directories. For example, "<emphasis>**/foo</emphasis>" matches file or directory
\r
176 "<emphasis>foo</emphasis>" anywhere, the same as pattern "<emphasis>foo</emphasis>". "<emphasis>**/foo/bar</emphasis>"
\r
177 matches file or directory "<emphasis>bar</emphasis>" anywhere that is directly
\r
178 under directory "<emphasis>foo</emphasis>".
\r
183 A trailing "<emphasis>/**</emphasis>" matches everything inside. For example,
\r
184 "<emphasis>abc/**</emphasis>" matches all files inside directory "<emphasis>abc</emphasis>", relative
\r
185 to the location of the <emphasis>.gitignore</emphasis> file, with infinite depth.
\r
190 A slash followed by two consecutive asterisks then a slash
\r
191 matches zero or more directories. For example, "<emphasis>a/**/b</emphasis>"
\r
192 matches "<emphasis>a/b</emphasis>", "<emphasis>a/x/b</emphasis>", "<emphasis>a/x/y/b</emphasis>" and so on.
\r
197 Other consecutive asterisks are considered regular asterisks and
\r
198 will match according to the previous rules.
\r
203 <simplesect id="gitignore(5)__configuration">
\r
204 <title>CONFIGURATION</title>
\r
205 <simpara>The optional configuration variable <emphasis>core.excludesFile</emphasis> indicates a path to a
\r
206 file containing patterns of file names to exclude, similar to
\r
207 <emphasis>$GIT_DIR/info/exclude</emphasis>. Patterns in the exclude file are used in addition to
\r
208 those in <emphasis>$GIT_DIR/info/exclude</emphasis>.</simpara>
\r
210 <simplesect id="gitignore(5)__notes">
\r
211 <title>NOTES</title>
\r
212 <simpara>The purpose of gitignore files is to ensure that certain files
\r
213 not tracked by Git remain untracked.</simpara>
\r
214 <simpara>To stop tracking a file that is currently tracked, use
\r
215 <emphasis>git rm --cached</emphasis>.</simpara>
\r
217 <simplesect id="gitignore(5)__examples">
\r
218 <title>EXAMPLES</title>
\r
222 The pattern <emphasis>hello.*</emphasis> matches any file or folder
\r
223 whose name begins with <emphasis>hello</emphasis>. If one wants to restrict
\r
224 this only to the directory and not in its subdirectories,
\r
225 one can prepend the pattern with a slash, i.e. <emphasis>/hello.*</emphasis>;
\r
226 the pattern now matches <emphasis>hello.txt</emphasis>, <emphasis>hello.c</emphasis> but not
\r
227 <emphasis>a/hello.java</emphasis>.
\r
232 The pattern <emphasis>foo/</emphasis> will match a directory <emphasis>foo</emphasis> and
\r
233 paths underneath it, but will not match a regular file
\r
234 or a symbolic link <emphasis>foo</emphasis> (this is consistent with the
\r
235 way how pathspec works in general in Git)
\r
240 The pattern <emphasis>doc/frotz</emphasis> and <emphasis>/doc/frotz</emphasis> have the same effect
\r
241 in any <emphasis>.gitignore</emphasis> file. In other words, a leading slash
\r
242 is not relevant if there is already a middle slash in
\r
248 The pattern "foo/*", matches "foo/test.json"
\r
249 (a regular file), "foo/bar" (a directory), but it does not match
\r
250 "foo/bar/hello.c" (a regular file), as the asterisk in the
\r
251 pattern does not match "bar/hello.c" which has a slash in it.
\r
255 <screen> $ git status
\r
259 # Documentation/foo.html
\r
260 # Documentation/gitignore.html
\r
265 $ cat .git/info/exclude
\r
266 # ignore objects and archives, anywhere in the tree.
\r
268 $ cat Documentation/.gitignore
\r
269 # ignore generated html files,
\r
271 # except foo.html which is maintained by hand
\r
277 # Documentation/foo.html
\r
279 <simpara>Another example:</simpara>
\r
280 <screen> $ cat .gitignore
\r
282 $ ls arch/foo/kernel/vm*
\r
283 arch/foo/kernel/vmlinux.lds.S
\r
284 $ echo '!/vmlinux*' >arch/foo/kernel/.gitignore</screen>
\r
285 <simpara>The second .gitignore prevents Git from ignoring
\r
286 <emphasis>arch/foo/kernel/vmlinux.lds.S</emphasis>.</simpara>
\r
287 <simpara>Example to exclude everything except a specific directory <emphasis>foo/bar</emphasis>
\r
288 (note the <emphasis>/*</emphasis> - without the slash, the wildcard would also exclude
\r
289 everything within <emphasis>foo/bar</emphasis>):</simpara>
\r
290 <screen> $ cat .gitignore
\r
291 # exclude everything except directory foo/bar
\r
297 <simplesect id="gitignore(5)__see_also">
\r
298 <title>SEE ALSO</title>
\r
299 <simpara><xref linkend="git-rm(1)" />,
\r
300 <xref linkend="gitrepository-layout(5)" />,
\r
301 <xref linkend="git-check-ignore(1)" /></simpara>
\r
303 <simplesect id="gitignore(5)__git">
\r
305 <simpara>Part of the <xref linkend="git(1)" /> suite</simpara>
\r