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 21order of precedence, from highest to lowest (within one level of 22precedence, the last matching pattern decides the outcome): 23 24 * Patterns read from the command line for those commands that support 25 them. 26 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. 35 36 * Patterns read from `$GIT_DIR/info/exclude`. 37 38 * Patterns read from the file specified by the configuration 39 variable 'core.excludesfile'. 40 41Which file to place a pattern in depends on how the pattern is meant to 42be used. Patterns which should be version-controlled and distributed to 43other repositories via clone (i.e., files that all developers will want 44to ignore) should go into a `.gitignore` file. Patterns which are 45specific to a particular repository but which do not need to be shared 46with other related repositories (e.g., auxiliary files that live inside 47the repository but are specific to one user's workflow) should go into 48the `$GIT_DIR/info/exclude` file. Patterns which a user wants git to 49ignore in all situations (e.g., backup or temporary files generated by 50the user's editor of choice) generally go into a file specified by 51`core.excludesfile` in the user's `~/.gitconfig`. 52 53The underlying git plumbing tools, such as 54linkgit:git-ls-files[1] and linkgit:git-read-tree[1], read 55`gitignore` patterns specified by command-line options, or from 56files specified by command-line options. Higher-level git 57tools, such as linkgit:git-status[1] and linkgit:git-add[1], 58use patterns from the sources specified above. 59 60Patterns have the following format: 61 62 - A blank line matches no files, so it can serve as a separator 63 for readability. 64 65 - A line starting with # serves as a comment. 66 67 - An optional prefix '!' which negates the pattern; any 68 matching file excluded by a previous pattern will become 69 included again. If a negated pattern matches, this will 70 override lower precedence patterns sources. 71 72 - If the pattern does not contain a slash '/', git treats it as 73 a shell glob pattern and checks for a match against the 74 pathname without leading directories. 75 76 - Otherwise, git treats the pattern as a shell glob suitable 77 for consumption by fnmatch(3) with the FNM_PATHNAME flag: 78 wildcards in the pattern will not match a / in the pathname. 79 For example, "Documentation/\*.html" matches 80 "Documentation/git.html" but not 81 "Documentation/ppc/ppc.html". A leading slash matches the 82 beginning of the pathname; for example, "/*.c" matches 83 "cat-file.c" but not "mozilla-sha1/sha1.c". 84 85An example: 86 87-------------------------------------------------------------- 88 $ git-status 89 [...] 90 # Untracked files: 91 [...] 92 # Documentation/foo.html 93 # Documentation/gitignore.html 94 # file.o 95 # lib.a 96 # src/internal.o 97 [...] 98 $ cat .git/info/exclude 99 # ignore objects and archives, anywhere in the tree. 100 *.[oa] 101 $ cat Documentation/.gitignore 102 # ignore generated html files, 103 *.html 104 # except foo.html which is maintained by hand 105 !foo.html 106 $ git-status 107 [...] 108 # Untracked files: 109 [...] 110 # Documentation/foo.html 111 [...] 112-------------------------------------------------------------- 113 114Another example: 115 116-------------------------------------------------------------- 117 $ cat .gitignore 118 vmlinux* 119 $ ls arch/foo/kernel/vm* 120 arch/foo/kernel/vmlinux.lds.S 121 $ echo '!/vmlinux*' >arch/foo/kernel/.gitignore 122-------------------------------------------------------------- 123 124The second .gitignore prevents git from ignoring 125`arch/foo/kernel/vmlinux.lds.S`. 126 127Documentation 128------------- 129Documentation by David Greaves, Junio C Hamano, Josh Triplett, 130Frank Lichtenheld, and the git-list <git@vger.kernel.org>. 131 132GIT 133--- 134Part of the linkgit:git[7] suite