3 .\" Author: [FIXME: author] [see http://www.docbook.org/tdg5/en/html/author]
4 .\" Generator: DocBook XSL Stylesheets v1.79.2 <http://docbook.sf.net/>
7 .\" Source: Git 2.47.0.rc0.18.ge9356ba3ea
10 .TH "GITIGNORE" "5" "2024-09-30" "Git 2\&.47\&.0\&.rc0\&.18\&.ge" "Git Manual"
11 .\" -----------------------------------------------------------------
12 .\" * Define some portability stuff
13 .\" -----------------------------------------------------------------
14 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15 .\" http://bugs.debian.org/507673
16 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
17 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
20 .\" -----------------------------------------------------------------
21 .\" * set default formatting
22 .\" -----------------------------------------------------------------
23 .\" disable hyphenation
25 .\" disable justification (adjust text to left margin only)
27 .\" -----------------------------------------------------------------
28 .\" * MAIN CONTENT STARTS HERE *
29 .\" -----------------------------------------------------------------
31 gitignore \- Specifies intentionally untracked files to ignore
34 $XDG_CONFIG_HOME/git/ignore, $GIT_DIR/info/exclude, \&.gitignore
37 A \fBgitignore\fR file specifies intentionally untracked files that Git should ignore\&. Files already tracked by Git are not affected; see the NOTES below for details\&.
39 Each line in a \fBgitignore\fR file specifies a pattern\&. When deciding whether to ignore a path, Git normally checks \fBgitignore\fR 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):
49 Patterns read from the command line for those commands that support them\&.
62 file in the same directory as the path, or in any parent directory (up to the top\-level of the working tree), with patterns in the higher level files being overridden by those in lower level files down to the directory containing the file\&. These patterns match relative to the location of the
64 file\&. A project normally includes such
66 files in its repository, containing patterns for files generated as part of the project build\&.
78 \fB$GIT_DIR/info/exclude\fR\&.
89 Patterns read from the file specified by the configuration variable
90 \fBcore\&.excludesFile\fR\&.
93 Which file to place a pattern in depends on how the pattern is meant to be used\&.
103 Patterns which should be version\-controlled and distributed to other repositories via clone (i\&.e\&., files that all developers will want to ignore) should go into a
116 Patterns which are specific to a particular repository but which do not need to be shared with other related repositories (e\&.g\&., auxiliary files that live inside the repository but are specific to one user\(cqs workflow) should go into the
117 \fB$GIT_DIR/info/exclude\fR
129 Patterns which a user wants Git to ignore in all situations (e\&.g\&., backup or temporary files generated by the user\(cqs editor of choice) generally go into a file specified by
130 \fBcore\&.excludesFile\fR
132 \fB~/\&.gitconfig\fR\&. Its default value is $XDG_CONFIG_HOME/git/ignore\&. If $XDG_CONFIG_HOME is either not set or empty, $HOME/\&.config/git/ignore is used instead\&.
135 The underlying Git plumbing tools, such as \fIgit ls\-files\fR and \fIgit read\-tree\fR, read \fBgitignore\fR patterns specified by command\-line options, or from files specified by command\-line options\&. Higher\-level Git tools, such as \fIgit status\fR and \fIgit add\fR, use patterns from the sources specified above\&.
146 A blank line matches no files, so it can serve as a separator for readability\&.
157 A line starting with # serves as a comment\&. Put a backslash ("\fB\e\fR") in front of the first hash for patterns that begin with a hash\&.
168 Trailing spaces are ignored unless they are quoted with backslash ("\fB\e\fR")\&.
179 An optional prefix "\fB!\fR" which negates the pattern; any matching file excluded by a previous pattern will become included again\&. It is not possible to re\-include a file if a parent directory of that file is excluded\&. Git doesn\(cqt list excluded directories for performance reasons, so any patterns on contained files have no effect, no matter where they are defined\&. Put a backslash ("\fB\e\fR") in front of the first "\fB!\fR" for patterns that begin with a literal "\fB!\fR", for example, "\fB\e!important!\&.txt\fR"\&.
190 The slash "\fB/\fR" is used as the directory separator\&. Separators may occur at the beginning, middle or end of the
203 If there is a separator at the beginning or middle (or both) of the pattern, then the pattern is relative to the directory level of the particular
205 file itself\&. Otherwise the pattern may also match at any level below the
218 If there is a separator at the end of the pattern then the pattern will only match directories, otherwise the pattern can match both files and directories\&.
229 For example, a pattern
241 that is a directory (all paths are relative from the
254 An asterisk "\fB*\fR" matches anything except a slash\&. The character "\fB?\fR" matches any one character except "\fB/\fR"\&. The range notation, e\&.g\&.
255 \fB[a\-zA\-Z]\fR, can be used to match one of the characters in a range\&. See fnmatch(3) and the FNM_PATHNAME flag for a more detailed description\&.
258 Two consecutive asterisks ("\fB**\fR") in patterns matched against full pathname may have special meaning:
268 A leading "\fB**\fR" followed by a slash means match in all directories\&. For example, "\fB**/foo\fR" matches file or directory "\fBfoo\fR" anywhere, the same as pattern "\fBfoo\fR"\&. "\fB**/foo/bar\fR" matches file or directory "\fBbar\fR" anywhere that is directly under directory "\fBfoo\fR"\&.
279 A trailing "\fB/**\fR" matches everything inside\&. For example, "\fBabc/**\fR" matches all files inside directory "\fBabc\fR", relative to the location of the
281 file, with infinite depth\&.
292 A slash followed by two consecutive asterisks then a slash matches zero or more directories\&. For example, "\fBa/**/b\fR" matches "\fBa/b\fR", "\fBa/x/b\fR", "\fBa/x/y/b\fR" and so on\&.
303 Other consecutive asterisks are considered regular asterisks and will match according to the previous rules\&.
307 The optional configuration variable \fBcore\&.excludesFile\fR indicates a path to a file containing patterns of file names to exclude, similar to \fB$GIT_DIR/info/exclude\fR\&. Patterns in the exclude file are used in addition to those in \fB$GIT_DIR/info/exclude\fR\&.
310 The purpose of gitignore files is to ensure that certain files not tracked by Git remain untracked\&.
312 To stop tracking a file that is currently tracked, use \fIgit rm \-\-cached\fR to remove the file from the index\&. The filename can then be added to the \fB\&.gitignore\fR file to stop the file from being reintroduced in later commits\&.
314 Git does not follow symbolic links when accessing a \fB\&.gitignore\fR file in the working tree\&. This keeps behavior consistent when the file is accessed from the index or a tree versus from the filesystem\&.
327 matches any file or directory whose name begins with
328 \fBhello\&.\fR\&. If one wants to restrict this only to the directory and not in its subdirectories, one can prepend the pattern with a slash, i\&.e\&.
329 \fB/hello\&.*\fR; the pattern now matches
333 \fBa/hello\&.java\fR\&.
346 will match a directory
348 and paths underneath it, but will not match a regular file or a symbolic link
350 (this is consistent with the way how pathspec works in general in Git)
365 have the same effect in any
367 file\&. In other words, a leading slash is not relevant if there is already a middle slash in the pattern\&.
380 \fBfoo/test\&.json\fR
383 (a directory), but it does not match
384 \fBfoo/bar/hello\&.c\fR
385 (a regular file), as the asterisk in the pattern does not match
387 which has a slash in it\&.
398 # Documentation/foo\&.html
399 # Documentation/gitignore\&.html
404 $ cat \&.git/info/exclude
405 # ignore objects and archives, anywhere in the tree\&.
407 $ cat Documentation/\&.gitignore
408 # ignore generated html files,
410 # except foo\&.html which is maintained by hand
416 # Documentation/foo\&.html
431 $ ls arch/foo/kernel/vm*
432 arch/foo/kernel/vmlinux\&.lds\&.S
433 $ echo \*(Aq!/vmlinux*\*(Aq >arch/foo/kernel/\&.gitignore
439 The second \&.gitignore prevents Git from ignoring \fBarch/foo/kernel/vmlinux\&.lds\&.S\fR\&.
441 Example to exclude everything except a specific directory \fBfoo/bar\fR (note the \fB/*\fR \- without the slash, the wildcard would also exclude everything within \fBfoo/bar\fR):
448 # exclude everything except directory foo/bar
459 \fBgit-rm\fR(1), \fBgitrepository-layout\fR(5), \fBgit-check-ignore\fR(1)
462 Part of the \fBgit\fR(1) suite