1GITIGNORE(5) Git Manual GITIGNORE(5)
2
3
4
6 gitignore - Specifies intentionally untracked files to ignore
7
9 $GIT_DIR/info/exclude, .gitignore
10
12 A gitignore file specifies intentionally untracked files that git
13 should ignore. Note that all the gitignore files really concern only
14 files that are not already tracked by git; in order to ignore
15 uncommitted changes in already tracked files, please refer to the git
16 update-index --assume-unchanged documentation.
17
18 Each line in a gitignore file specifies a pattern. When deciding
19 whether to ignore a path, git normally checks gitignore patterns from
20 multiple sources, with the following order of precedence, from highest
21 to lowest (within one level of precedence, the last matching pattern
22 decides the outcome):
23
24 · Patterns read from the command line for those commands that support
25 them.
26
27 · Patterns read from a .gitignore file in the same directory as the
28 path, or in any parent directory, with patterns in the higher level
29 files (up to the toplevel of the work tree) being overridden by
30 those in lower level files down to the directory containing the
31 file. These patterns match relative to the location of the
32 .gitignore file. A project normally includes such .gitignore files
33 in its repository, containing patterns for files generated as part
34 of the project build.
35
36 · Patterns read from $GIT_DIR/info/exclude.
37
38 · Patterns read from the file specified by the configuration variable
39 core.excludesfile.
40
41 Which file to place a pattern in depends on how the pattern is meant to
42 be used. Patterns which should be version-controlled and distributed to
43 other repositories via clone (i.e., files that all developers will want
44 to ignore) should go into a .gitignore file. Patterns which are
45 specific to a particular repository but which do not need to be shared
46 with other related repositories (e.g., auxiliary files that live inside
47 the repository but are specific to one user’s workflow) should go into
48 the $GIT_DIR/info/exclude file. Patterns which a user wants git to
49 ignore in all situations (e.g., backup or temporary files generated by
50 the user’s editor of choice) generally go into a file specified by
51 core.excludesfile in the user’s ~/.gitconfig.
52
53 The underlying git plumbing tools, such as git ls-files and git
54 read-tree, read gitignore patterns specified by command-line options,
55 or from files specified by command-line options. Higher-level git
56 tools, such as git status and git add, use patterns from the sources
57 specified above.
58
59 Patterns have the following format:
60
61 · A blank line matches no files, so it can serve as a separator for
62 readability.
63
64 · A line starting with # serves as a comment.
65
66 · An optional prefix ! which negates the pattern; any matching file
67 excluded by a previous pattern will become included again. If a
68 negated pattern matches, this will override lower precedence
69 patterns sources.
70
71 · If the pattern ends with a slash, it is removed for the purpose of
72 the following description, but it would only find a match with a
73 directory. In other words, foo/ will match a directory foo and
74 paths underneath it, but will not match a regular file or a
75 symbolic link foo (this is consistent with the way how pathspec
76 works in general in git).
77
78 · If the pattern does not contain a slash /, git treats it as a shell
79 glob pattern and checks for a match against the pathname without
80 leading directories.
81
82 · Otherwise, git treats the pattern as a shell glob suitable for
83 consumption by fnmatch(3) with the FNM_PATHNAME flag: wildcards in
84 the pattern will not match a / in the pathname. For example,
85 "Documentation/*.html" matches "Documentation/git.html" but not
86 "Documentation/ppc/ppc.html". A leading slash matches the beginning
87 of the pathname; for example, "/*.c" matches "cat-file.c" but not
88 "mozilla-sha1/sha1.c".
89
90 An example:
91
92 $ git status
93 [...]
94 # Untracked files:
95 [...]
96 # Documentation/foo.html
97 # Documentation/gitignore.html
98 # file.o
99 # lib.a
100 # src/internal.o
101 [...]
102 $ cat .git/info/exclude
103 # ignore objects and archives, anywhere in the tree.
104 *.[oa]
105 $ cat Documentation/.gitignore
106 # ignore generated html files,
107 *.html
108 # except foo.html which is maintained by hand
109 !foo.html
110 $ git status
111 [...]
112 # Untracked files:
113 [...]
114 # Documentation/foo.html
115 [...]
116
117
118 Another example:
119
120 $ cat .gitignore
121 vmlinux*
122 $ ls arch/foo/kernel/vm*
123 arch/foo/kernel/vmlinux.lds.S
124 $ echo ´!/vmlinux*´ >arch/foo/kernel/.gitignore
125
126
127 The second .gitignore prevents git from ignoring
128 arch/foo/kernel/vmlinux.lds.S.
129
131 Documentation by David Greaves, Junio C Hamano, Josh Triplett, Frank
132 Lichtenheld, and the git-list <git@vger.kernel.org[1]>.
133
135 Part of the git(1) suite
136
138 1. git@vger.kernel.org
139 mailto:git@vger.kernel.org
140
141
142
143Git 1.7.1 08/16/2017 GITIGNORE(5)