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