1GITIGNORE(5)                      Git Manual                      GITIGNORE(5)
2
3
4

NAME

6       gitignore - Specifies intentionally untracked files to ignore
7

SYNOPSIS

9       $GIT_DIR/info/exclude, .gitignore
10

DESCRIPTION

12       A gitignore file specifies intentionally untracked files that git
13       should ignore. Files already tracked by git are not affected; see the
14       NOTES below for details.
15
16       Each line in a gitignore file specifies a pattern. When deciding
17       whether to ignore a path, git normally checks gitignore patterns from
18       multiple sources, with the following order of precedence, from highest
19       to lowest (within one level of precedence, the last matching pattern
20       decides the outcome):
21
22       ·   Patterns read from the command line for those commands that support
23           them.
24
25       ·   Patterns read from a .gitignore file in the same directory as the
26           path, or in any parent directory, with patterns in the higher level
27           files (up to the toplevel of the work tree) being overridden by
28           those in lower level files down to the directory containing the
29           file. These patterns match relative to the location of the
30           .gitignore file. A project normally includes such .gitignore files
31           in its repository, containing patterns for files generated as part
32           of the project build.
33
34       ·   Patterns read from $GIT_DIR/info/exclude.
35
36       ·   Patterns read from the file specified by the configuration variable
37           core.excludesfile.
38
39       Which file to place a pattern in depends on how the pattern is meant to
40       be used. Patterns which should be version-controlled and distributed to
41       other repositories via clone (i.e., files that all developers will want
42       to ignore) should go into a .gitignore file. Patterns which are
43       specific to a particular repository but which do not need to be shared
44       with other related repositories (e.g., auxiliary files that live inside
45       the repository but are specific to one user’s workflow) should go into
46       the $GIT_DIR/info/exclude file. Patterns which a user wants git to
47       ignore in all situations (e.g., backup or temporary files generated by
48       the user’s editor of choice) generally go into a file specified by
49       core.excludesfile in the user’s ~/.gitconfig.
50
51       The underlying git plumbing tools, such as git ls-files and git
52       read-tree, read gitignore patterns specified by command-line options,
53       or from files specified by command-line options. Higher-level git
54       tools, such as git status and git add, use patterns from the sources
55       specified above.
56

PATTERN FORMAT

58       ·   A blank line matches no files, so it can serve as a separator for
59           readability.
60
61       ·   A line starting with # serves as a comment.
62
63       ·   An optional prefix !  which negates the pattern; any matching file
64           excluded by a previous pattern will become included again. If a
65           negated pattern matches, this will override lower precedence
66           patterns sources.
67
68       ·   If the pattern ends with a slash, it is removed for the purpose of
69           the following description, but it would only find a match with a
70           directory. In other words, foo/ will match a directory foo and
71           paths underneath it, but will not match a regular file or a
72           symbolic link foo (this is consistent with the way how pathspec
73           works in general in git).
74
75       ·   If the pattern does not contain a slash /, git treats it as a shell
76           glob pattern and checks for a match against the pathname relative
77           to the location of the .gitignore file (relative to the toplevel of
78           the work tree if not from a .gitignore file).
79
80       ·   Otherwise, git treats the pattern as a shell glob suitable for
81           consumption by fnmatch(3) with the FNM_PATHNAME flag: wildcards in
82           the pattern will not match a / in the pathname. For example,
83           "Documentation/*.html" matches "Documentation/git.html" but not
84           "Documentation/ppc/ppc.html" or
85           "tools/perf/Documentation/perf.html".
86
87       ·   A leading slash matches the beginning of the pathname. For example,
88           "/*.c" matches "cat-file.c" but not "mozilla-sha1/sha1.c".
89

NOTES

91       The purpose of gitignore files is to ensure that certain files not
92       tracked by git remain untracked.
93
94       To ignore uncommitted changes in a file that is already tracked, use
95       git update-index --assume-unchanged.
96
97       To stop tracking a file that is currently tracked, use git rm --cached.
98

EXAMPLES

100               $ git status
101               [...]
102               # Untracked files:
103               [...]
104               #       Documentation/foo.html
105               #       Documentation/gitignore.html
106               #       file.o
107               #       lib.a
108               #       src/internal.o
109               [...]
110               $ cat .git/info/exclude
111               # ignore objects and archives, anywhere in the tree.
112               *.[oa]
113               $ cat Documentation/.gitignore
114               # ignore generated html files,
115               *.html
116               # except foo.html which is maintained by hand
117               !foo.html
118               $ git status
119               [...]
120               # Untracked files:
121               [...]
122               #       Documentation/foo.html
123               [...]
124
125
126       Another example:
127
128               $ cat .gitignore
129               vmlinux*
130               $ ls arch/foo/kernel/vm*
131               arch/foo/kernel/vmlinux.lds.S
132               $ echo '!/vmlinux*' >arch/foo/kernel/.gitignore
133
134
135       The second .gitignore prevents git from ignoring
136       arch/foo/kernel/vmlinux.lds.S.
137

SEE ALSO

139       git-rm(1), git-update-index(1), gitrepository-layout(5)
140

DOCUMENTATION

142       Documentation by David Greaves, Junio C Hamano, Josh Triplett, Frank
143       Lichtenheld, and the git-list <git@vger.kernel.org[1]>.
144

GIT

146       Part of the git(1) suite
147

NOTES

149        1. git@vger.kernel.org
150           mailto:git@vger.kernel.org
151
152
153
154Git 1.7.4.4                       04/11/2011                      GITIGNORE(5)
Impressum