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 overridden 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 linkgit:git-ls-files[1] and linkgit: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 linkgit:git-status[1] and linkgit: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 ends with a slash, it is removed for the
61 purpose of the following description, but it would only find
62 a match with a directory. In other words, `foo/` will match a
63 directory `foo` and paths underneath it, but will not match a
64 regular file or a symbolic link `foo` (this is consistent
65 with the way how pathspec works in general in git).
67 - If the pattern does not contain a slash '/', git treats it as
68 a shell glob pattern and checks for a match against the
69 pathname without leading directories.
71 - Otherwise, git treats the pattern as a shell glob suitable
72 for consumption by fnmatch(3) with the FNM_PATHNAME flag:
73 wildcards in the pattern will not match a / in the pathname.
74 For example, "Documentation/\*.html" matches
75 "Documentation/git.html" but not
76 "Documentation/ppc/ppc.html". A leading slash matches the
77 beginning of the pathname; for example, "/*.c" matches
78 "cat-file.c" but not "mozilla-sha1/sha1.c".
82 --------------------------------------------------------------
87 # Documentation/foo.html
88 # Documentation/gitignore.html
93 $ cat .git/info/exclude
94 # ignore objects and archives, anywhere in the tree.
96 $ cat Documentation/.gitignore
97 # ignore generated html files,
99 # except foo.html which is maintained by hand
105 # Documentation/foo.html
107 --------------------------------------------------------------
111 --------------------------------------------------------------
114 $ ls arch/foo/kernel/vm*
115 arch/foo/kernel/vmlinux.lds.S
116 $ echo '!/vmlinux*' >arch/foo/kernel/.gitignore
117 --------------------------------------------------------------
119 The second .gitignore prevents git from ignoring
120 `arch/foo/kernel/vmlinux.lds.S`.
124 Documentation by David Greaves, Junio C Hamano, Josh Triplett,
125 Frank Lichtenheld, and the git-list <git@vger.kernel.org>.
129 Part of the linkgit:git[7] suite