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

NAME

6       gitignore - Specifies intentionally untracked files to ignore
7

SYNOPSIS

9       $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       ·   An optional prefix "!" which negates the pattern; any matching file
72           excluded by a previous pattern will become included again. If a
73           negated pattern matches, this will override lower precedence
74           patterns sources. Put a backslash ("\") in front of the first "!"
75           for patterns that begin with a literal "!", for example,
76           "\!important!.txt".
77
78       ·   If the pattern ends with a slash, it is removed for the purpose of
79           the following description, but it would only find a match with a
80           directory. In other words, foo/ will match a directory foo and
81           paths underneath it, but will not match a regular file or a
82           symbolic link foo (this is consistent with the way how pathspec
83           works in general in Git).
84
85       ·   If the pattern does not contain a slash /, Git treats it as a shell
86           glob pattern and checks for a match against the pathname relative
87           to the location of the .gitignore file (relative to the toplevel of
88           the work tree if not from a .gitignore file).
89
90       ·   Otherwise, Git treats the pattern as a shell glob suitable for
91           consumption by fnmatch(3) with the FNM_PATHNAME flag: wildcards in
92           the pattern will not match a / in the pathname. For example,
93           "Documentation/*.html" matches "Documentation/git.html" but not
94           "Documentation/ppc/ppc.html" or
95           "tools/perf/Documentation/perf.html".
96
97       ·   A leading slash matches the beginning of the pathname. For example,
98           "/*.c" matches "cat-file.c" but not "mozilla-sha1/sha1.c".
99
100       Two consecutive asterisks ("**") in patterns matched against full
101       pathname may have special meaning:
102
103       ·   A leading "**" followed by a slash means match in all directories.
104           For example, "**/foo" matches file or directory "foo" anywhere, the
105           same as pattern "foo". "**/foo/bar" matches file or directory "bar"
106           anywhere that is directly under directory "foo".
107
108       ·   A trailing "/" matches everything inside. For example, "abc/"
109           matches all files inside directory "abc", relative to the location
110           of the .gitignore file, with infinite depth.
111
112       ·   A slash followed by two consecutive asterisks then a slash matches
113           zero or more directories. For example, "a/**/b" matches "a/b",
114           "a/x/b", "a/x/y/b" and so on.
115
116       ·   Other consecutive asterisks are considered invalid.
117

NOTES

119       The purpose of gitignore files is to ensure that certain files not
120       tracked by Git remain untracked.
121
122       To ignore uncommitted changes in a file that is already tracked, use
123       git update-index --assume-unchanged.
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

SEE ALSO

167       git-rm(1), git-update-index(1), gitrepository-layout(5), git-check-
168       ignore(1)
169

GIT

171       Part of the git(1) suite
172
173
174
175Git 1.8.3.1                       11/19/2018                      GITIGNORE(5)
Impressum