Documentation / gitignore.txton commit Retire git-runstatus for real. (fa47016)
   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
  41The underlying git plumbing tools, such as
  42gitlink:git-ls-files[1] and gitlink:git-read-tree[1], read
  43`gitignore` patterns specified by command-line options, or from
  44files specified by command-line options.  Higher-level git
  45tools, such as gitlink:git-status[1] and gitlink:git-add[1],
  46use patterns from the sources specified above.
  47
  48Patterns have the following format:
  49
  50 - A blank line matches no files, so it can serve as a separator
  51   for readability.
  52
  53 - A line starting with # serves as a comment.
  54
  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.
  59
  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.
  63
  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".
  72
  73An example:
  74
  75--------------------------------------------------------------
  76    $ git-status
  77    [...]
  78    # Untracked files:
  79    [...]
  80    #       Documentation/foo.html
  81    #       Documentation/gitignore.html
  82    #       file.o
  83    #       lib.a
  84    #       src/internal.o
  85    [...]
  86    $ cat .git/info/exclude
  87    # ignore objects and archives, anywhere in the tree.
  88    *.[oa]
  89    $ cat Documentation/.gitignore
  90    # ignore generated html files,
  91    *.html
  92    # except foo.html which is maintained by hand
  93    !foo.html
  94    $ git-status
  95    [...]
  96    # Untracked files:
  97    [...]
  98    #       Documentation/foo.html
  99    [...]
 100--------------------------------------------------------------
 101
 102Another example:
 103
 104--------------------------------------------------------------
 105    $ cat .gitignore
 106    vmlinux*
 107    $ ls arch/foo/kernel/vm*
 108    arch/foo/kernel/vmlinux.lds.S
 109    $ echo '!/vmlinux*' >arch/foo/kernel/.gitignore
 110--------------------------------------------------------------
 111
 112The second .gitignore prevents git from ignoring
 113`arch/foo/kernel/vmlinux.lds.S`.
 114
 115Documentation
 116-------------
 117Documentation by David Greaves, Junio C Hamano, Josh Triplett,
 118Frank Lichtenheld, and the git-list <git@vger.kernel.org>.
 119
 120GIT
 121---
 122Part of the gitlink:git[7] suite