6 gitignore - Specifies intentionally untracked files to ignore
10 $GIT_DIR/info/exclude, .gitignore
15 A `gitignore` file specifies intentionally untracked files that
16 git should ignore. Each line in a `gitignore` file specifies a
19 When deciding whether to ignore a path, git normally checks
20 `gitignore` patterns from multiple sources, with the following
21 order of precedence, from highest to lowest (within one level of
22 precedence, the last matching pattern decides the outcome):
24 * Patterns read from the command line for those commands that support
27 * Patterns read from a `.gitignore` file in the same directory
28 as the path, or in any parent directory, with patterns in the
29 higher level files (up to the root) being overriden by those in
30 lower level files down to the directory containing the file.
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.
36 * Patterns read from `$GIT_DIR/info/exclude`.
38 * Patterns read from the file specified by the configuration
39 variable 'core.excludesfile'.
41 The underlying git plumbing tools, such as
42 gitlink:git-ls-files[1] and gitlink:git-read-tree[1], read
43 `gitignore` patterns specified by command-line options, or from
44 files specified by command-line options. Higher-level git
45 tools, such as gitlink:git-status[1] and gitlink:git-add[1],
46 use patterns from the sources specified above.
48 Patterns have the following format:
50 - A blank line matches no files, so it can serve as a separator
53 - A line starting with # serves as a comment.
55 - An optional prefix '!' which negates the pattern; any
56 matching file excluded by a previous pattern will become
57 included again. If a negated pattern matches, this will
58 override lower precedence patterns sources.
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.
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".
75 --------------------------------------------------------------
80 # Documentation/foo.html
81 # Documentation/gitignore.html
86 $ cat .git/info/exclude
87 # ignore objects and archives, anywhere in the tree.
89 $ cat Documentation/.gitignore
90 # ignore generated html files,
92 # except foo.html which is maintained by hand
98 # Documentation/foo.html
100 --------------------------------------------------------------
104 --------------------------------------------------------------
107 $ ls arch/foo/kernel/vm*
108 arch/foo/kernel/vmlinux.lds.S
109 $ echo '!/vmlinux*' >arch/foo/kernel/.gitignore
110 --------------------------------------------------------------
112 The second .gitignore prevents git from ignoring
113 `arch/foo/kernel/vmlinux.lds.S`.
117 Documentation by David Greaves, Junio C Hamano, Josh Triplett,
118 Frank Lichtenheld, and the git-list <git@vger.kernel.org>.
122 Part of the gitlink:git[7] suite