| Junio C Hamano | 679d22d | 2007-06-02 21:13:44 | [diff] [blame] | 1 | gitignore(5) |
| 2 | ============ |
| 3 | |
| 4 | NAME |
| 5 | ---- |
| 6 | gitignore - Specifies intentionally untracked files to ignore |
| 7 | |
| 8 | SYNOPSIS |
| 9 | -------- |
| 10 | $GIT_DIR/info/exclude, .gitignore |
| 11 | |
| 12 | DESCRIPTION |
| 13 | ----------- |
| 14 | |
| 15 | A `gitignore` file specifies intentionally untracked files that |
| 16 | git should ignore. Each line in a `gitignore` file specifies a |
| 17 | pattern. |
| 18 | |
| 19 | When deciding whether to ignore a path, git normally checks |
| 20 | `gitignore` patterns from multiple sources, with the following |
| Junio C Hamano | de9879a | 2007-07-22 09:33:42 | [diff] [blame] | 21 | order of precedence, from highest to lowest (within one level of |
| 22 | precedence, the last matching pattern decides the outcome): |
| Junio C Hamano | 679d22d | 2007-06-02 21:13:44 | [diff] [blame] | 23 | |
| Junio C Hamano | de9879a | 2007-07-22 09:33:42 | [diff] [blame] | 24 | * Patterns read from the command line for those commands that support |
| 25 | them. |
| Junio C Hamano | 679d22d | 2007-06-02 21:13:44 | [diff] [blame] | 26 | |
| 27 | * Patterns read from a `.gitignore` file in the same directory |
| Junio C Hamano | de9879a | 2007-07-22 09:33:42 | [diff] [blame] | 28 | as the path, or in any parent directory, with patterns in the |
| Junio C Hamano | 4fd58d4 | 2007-09-30 00:51:14 | [diff] [blame] | 29 | higher level files (up to the root) being overridden by those in |
| Junio C Hamano | de9879a | 2007-07-22 09:33:42 | [diff] [blame] | 30 | lower level files down to the directory containing the file. |
| Junio C Hamano | 679d22d | 2007-06-02 21:13:44 | [diff] [blame] | 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 | |
| Junio C Hamano | de9879a | 2007-07-22 09:33:42 | [diff] [blame] | 36 | * Patterns read from `$GIT_DIR/info/exclude`. |
| 37 | |
| 38 | * Patterns read from the file specified by the configuration |
| 39 | variable 'core.excludesfile'. |
| 40 | |
| Junio C Hamano | 99dc24a | 2008-03-27 23:49:50 | [diff] [blame] | 41 | Which file to place a pattern in depends on how the pattern is meant to |
| 42 | be used. Patterns which should be version-controlled and distributed to |
| 43 | other repositories via clone (i.e., files that all developers will want |
| 44 | to ignore) should go into a `.gitignore` file. Patterns which are |
| 45 | specific to a particular repository but which do not need to be shared |
| 46 | with other related repositories (e.g., auxiliary files that live inside |
| 47 | the repository but are specific to one user's workflow) should go into |
| 48 | the `$GIT_DIR/info/exclude` file. Patterns which a user wants git to |
| 49 | ignore in all situations (e.g., backup or temporary files generated by |
| 50 | the user's editor of choice) generally go into a file specified by |
| 51 | `core.excludesfile` in the user's `~/.gitconfig`. |
| 52 | |
| Junio C Hamano | 679d22d | 2007-06-02 21:13:44 | [diff] [blame] | 53 | The underlying git plumbing tools, such as |
| Junio C Hamano | 35738e8 | 2008-01-07 07:55:46 | [diff] [blame] | 54 | linkgit:git-ls-files[1] and linkgit:git-read-tree[1], read |
| Junio C Hamano | 679d22d | 2007-06-02 21:13:44 | [diff] [blame] | 55 | `gitignore` patterns specified by command-line options, or from |
| 56 | files specified by command-line options. Higher-level git |
| Junio C Hamano | 35738e8 | 2008-01-07 07:55:46 | [diff] [blame] | 57 | tools, such as linkgit:git-status[1] and linkgit:git-add[1], |
| Junio C Hamano | 679d22d | 2007-06-02 21:13:44 | [diff] [blame] | 58 | use patterns from the sources specified above. |
| 59 | |
| 60 | Patterns 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 |
| Junio C Hamano | de9879a | 2007-07-22 09:33:42 | [diff] [blame] | 69 | included again. If a negated pattern matches, this will |
| 70 | override lower precedence patterns sources. |
| Junio C Hamano | 679d22d | 2007-06-02 21:13:44 | [diff] [blame] | 71 | |
| Junio C Hamano | 26e590a | 2008-02-17 03:53:51 | [diff] [blame] | 72 | - If the pattern ends with a slash, it is removed for the |
| 73 | purpose of the following description, but it would only find |
| 74 | a match with a directory. In other words, `foo/` will match a |
| 75 | directory `foo` and paths underneath it, but will not match a |
| 76 | regular file or a symbolic link `foo` (this is consistent |
| 77 | with the way how pathspec works in general in git). |
| 78 | |
| Junio C Hamano | 679d22d | 2007-06-02 21:13:44 | [diff] [blame] | 79 | - If the pattern does not contain a slash '/', git treats it as |
| 80 | a shell glob pattern and checks for a match against the |
| 81 | pathname without leading directories. |
| 82 | |
| 83 | - Otherwise, git treats the pattern as a shell glob suitable |
| 84 | for consumption by fnmatch(3) with the FNM_PATHNAME flag: |
| 85 | wildcards in the pattern will not match a / in the pathname. |
| 86 | For example, "Documentation/\*.html" matches |
| 87 | "Documentation/git.html" but not |
| 88 | "Documentation/ppc/ppc.html". A leading slash matches the |
| 89 | beginning of the pathname; for example, "/*.c" matches |
| 90 | "cat-file.c" but not "mozilla-sha1/sha1.c". |
| 91 | |
| 92 | An example: |
| 93 | |
| 94 | -------------------------------------------------------------- |
| 95 | $ git-status |
| 96 | [...] |
| 97 | # Untracked files: |
| 98 | [...] |
| 99 | # Documentation/foo.html |
| 100 | # Documentation/gitignore.html |
| 101 | # file.o |
| 102 | # lib.a |
| 103 | # src/internal.o |
| 104 | [...] |
| 105 | $ cat .git/info/exclude |
| 106 | # ignore objects and archives, anywhere in the tree. |
| 107 | *.[oa] |
| 108 | $ cat Documentation/.gitignore |
| 109 | # ignore generated html files, |
| 110 | *.html |
| 111 | # except foo.html which is maintained by hand |
| 112 | !foo.html |
| 113 | $ git-status |
| 114 | [...] |
| 115 | # Untracked files: |
| 116 | [...] |
| 117 | # Documentation/foo.html |
| 118 | [...] |
| 119 | -------------------------------------------------------------- |
| 120 | |
| 121 | Another example: |
| 122 | |
| 123 | -------------------------------------------------------------- |
| 124 | $ cat .gitignore |
| 125 | vmlinux* |
| 126 | $ ls arch/foo/kernel/vm* |
| 127 | arch/foo/kernel/vmlinux.lds.S |
| 128 | $ echo '!/vmlinux*' >arch/foo/kernel/.gitignore |
| 129 | -------------------------------------------------------------- |
| 130 | |
| 131 | The second .gitignore prevents git from ignoring |
| 132 | `arch/foo/kernel/vmlinux.lds.S`. |
| 133 | |
| 134 | Documentation |
| 135 | ------------- |
| 136 | Documentation by David Greaves, Junio C Hamano, Josh Triplett, |
| 137 | Frank Lichtenheld, and the git-list <git@vger.kernel.org>. |
| 138 | |
| 139 | GIT |
| 140 | --- |
| Junio C Hamano | f7c042d | 2008-06-06 22:50:53 | [diff] [blame] | 141 | Part of the linkgit:git[1] suite |