3 .\" Author: [FIXME: author] [see http://www.docbook.org/tdg5/en/html/author]
4 .\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
7 .\" Source: Git 2.39.0.137.g6bae53b138
10 .TH "GITIGNORE" "5" "12/28/2022" "Git 2\&.39\&.0\&.137\&.g6bae53" "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"\&.
192 is used as the directory separator\&. Separators may occur at the beginning, middle or end of the
205 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
207 file itself\&. Otherwise the pattern may also match at any level below the
220 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\&.
231 For example, a pattern
243 that is a directory (all paths are relative from the
256 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\&.
257 \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\&.
260 Two consecutive asterisks ("\fB**\fR") in patterns matched against full pathname may have special meaning:
270 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"\&.
281 A trailing "\fB/**\fR" matches everything inside\&. For example, "\fBabc/**\fR" matches all files inside directory "\fBabc\fR", relative to the location of the
283 file, with infinite depth\&.
294 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\&.
305 Other consecutive asterisks are considered regular asterisks and will match according to the previous rules\&.
309 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\&.
312 The purpose of gitignore files is to ensure that certain files not tracked by Git remain untracked\&.
314 To stop tracking a file that is currently tracked, use \fIgit rm \-\-cached\fR\&.
316 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\&.
329 matches any file or directory whose name begins with
330 \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\&.
331 \fB/hello\&.*\fR; the pattern now matches
335 \fBa/hello\&.java\fR\&.
348 will match a directory
350 and paths underneath it, but will not match a regular file or a symbolic link
352 (this is consistent with the way how pathspec works in general in Git)
367 have the same effect in any
369 file\&. In other words, a leading slash is not relevant if there is already a middle slash in the pattern\&.
380 The pattern "foo/*", matches "foo/test\&.json" (a regular file), "foo/bar" (a directory), but it does not match "foo/bar/hello\&.c" (a regular file), as the asterisk in the pattern does not match "bar/hello\&.c" which has a slash in it\&.
391 # Documentation/foo\&.html
392 # Documentation/gitignore\&.html
397 $ cat \&.git/info/exclude
398 # ignore objects and archives, anywhere in the tree\&.
400 $ cat Documentation/\&.gitignore
401 # ignore generated html files,
403 # except foo\&.html which is maintained by hand
409 # Documentation/foo\&.html
425 $ ls arch/foo/kernel/vm*
426 arch/foo/kernel/vmlinux\&.lds\&.S
427 $ echo \(aq!/vmlinux*\(aq >arch/foo/kernel/\&.gitignore
434 The second \&.gitignore prevents Git from ignoring \fBarch/foo/kernel/vmlinux\&.lds\&.S\fR\&.
436 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):
443 # exclude everything except directory foo/bar
455 \fBgit-rm\fR(1), \fBgitrepository-layout\fR(5), \fBgit-check-ignore\fR(1)
458 Part of the \fBgit\fR(1) suite