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. Each line in a gitignore file specifies a pattern.
14
15 When deciding whether to ignore a path, git normally checks gitignore
16 patterns from multiple sources, with the following order of precedence,
17 from highest to lowest (within one level of precedence, the last
18 matching pattern decides the outcome):
19
20
21 · Patterns read from the command line for those commands that support
22 them.
23
24 · Patterns read from a .gitignore file in the same directory as the
25 path, or in any parent directory, with patterns in the higher level
26 files (up to the root) being overridden by those in lower level
27 files down to the directory containing the file. These patterns
28 match relative to the location of the .gitignore file. A project
29 normally includes such .gitignore files in its repository,
30 containing patterns for files generated as part of the project
31 build.
32
33 · Patterns read from $GIT_DIR/info/exclude.
34
35 · Patterns read from the file specified by the configuration variable
36 core.excludesfile.
37 The underlying git plumbing tools, such as git-ls-files(1) and git-
38 read-tree(1), read gitignore patterns specified by command-line
39 options, or from files specified by command-line options. Higher-level
40 git tools, such as git-status(1) and git-add(1), use patterns from the
41 sources specified above.
42
43 Patterns have the following format:
44
45
46 · A blank line matches no files, so it can serve as a separator for
47 readability.
48
49 · A line starting with # serves as a comment.
50
51 · An optional prefix ! which negates the pattern; any matching file
52 excluded by a previous pattern will become included again. If a
53 negated pattern matches, this will override lower precedence
54 patterns sources.
55
56 · If the pattern does not contain a slash /, git treats it as a shell
57 glob pattern and checks for a match against the pathname without
58 leading directories.
59
60 · Otherwise, git treats the pattern as a shell glob suitable for
61 consumption by fnmatch(3) with the FNM_PATHNAME flag: wildcards in
62 the pattern will not match a / in the pathname. For example,
63 "Documentation/*.html" matches "Documentation/git.html" but not
64 "Documentation/ppc/ppc.html". A leading slash matches the beginning
65 of the pathname; for example, "/*.c" matches "cat-file.c" but not
66 "mozilla-sha1/sha1.c".
67 An example:
68
69
70
71 $ git-status
72 [...]
73 # Untracked files:
74 [...]
75 # Documentation/foo.html
76 # Documentation/gitignore.html
77 # file.o
78 # lib.a
79 # src/internal.o
80 [...]
81 $ cat .git/info/exclude
82 # ignore objects and archives, anywhere in the tree.
83 *.[oa]
84 $ cat Documentation/.gitignore
85 # ignore generated html files,
86 *.html
87 # except foo.html which is maintained by hand
88 !foo.html
89 $ git-status
90 [...]
91 # Untracked files:
92 [...]
93 # Documentation/foo.html
94 [...]
95
96 Another example:
97
98
99
100 $ cat .gitignore
101 vmlinux*
102 $ ls arch/foo/kernel/vm*
103 arch/foo/kernel/vmlinux.lds.S
104 $ echo ´!/vmlinux*´ >arch/foo/kernel/.gitignore
105
106 The second .gitignore prevents git from ignoring
107 arch/foo/kernel/vmlinux.lds.S.
108
110 Documentation by David Greaves, Junio C Hamano, Josh Triplett, Frank
111 Lichtenheld, and the git-list <git@vger.kernel.org>.
112
114 Part of the git(7) suite
115
116
117
118
119Git 1.5.3.3 10/09/2007 GITIGNORE(5)