NAME

git-check-ignore - Debug gitignore / exclude files

SYNOPSIS

  1. git check-ignore [<options>] <pathname>…​
  2. git check-ignore [<options>] --stdin

DESCRIPTION

For each pathname given via the command-line or from a file via—stdin, check whether the file is excluded by .gitignore (or otherinput files to the exclude mechanism) and output the path if it isexcluded.

By default, tracked files are not shown at all since they are notsubject to exclude rules; but see ‘—no-index’.

OPTIONS

  • -q, —quiet
  • Don’t output anything, just set exit status. This is onlyvalid with a single pathname.

  • -v, —verbose

  • Also output details about the matching pattern (if any)for each given pathname. For precedence rules within andbetween exclude sources, see gitignore[5].

  • —stdin

  • Read pathnames from the standard input, one per line,instead of from the command-line.

  • -z

  • The output format is modified to be machine-parseable (seebelow). If —stdin is also given, input paths are separatedwith a NUL character instead of a linefeed character.

  • -n, —non-matching

  • Show given paths which don’t match any pattern. This onlymakes sense when —verbose is enabled, otherwise it wouldnot be possible to distinguish between paths which match apattern and those which don’t.

  • —no-index

  • Don’t look in the index when undertaking the checks. This canbe used to debug why a path became tracked by e.g. git add .and was not ignored by the rules as expected by the user or whendeveloping patterns including negation to match a path previouslyadded with git add -f.

OUTPUT

By default, any of the given pathnames which match an ignore patternwill be output, one per line. If no pattern matches a given path,nothing will be output for that path; this means that path will not beignored.

If —verbose is specified, the output is a series of lines of the form:

<source> <COLON> <linenum> <COLON> <pattern> <HT> <pathname>

<pathname> is the path of a file being queried, <pattern> is thematching pattern, <source> is the pattern’s source file, and <linenum>is the line number of the pattern within that source. If the patterncontained a ! prefix or / suffix, it will be preserved in theoutput. <source> will be an absolute path when referring to the fileconfigured by core.excludesFile, or relative to the repository rootwhen referring to .git/info/exclude or a per-directory exclude file.

If -z is specified, the pathnames in the output are delimited by thenull character; if —verbose is also specified then null charactersare also used instead of colons and hard tabs:

<source> <NULL> <linenum> <NULL> <pattern> <NULL> <pathname> <NULL>

If -n or —non-matching are specified, non-matching pathnames willalso be output, in which case all fields in each output record exceptfor <pathname> will be empty. This can be useful when runningnon-interactively, so that files can be incrementally streamed toSTDIN of a long-running check-ignore process, and for each of thesefiles, STDOUT will indicate whether that file matched a pattern ornot. (Without this option, it would be impossible to tell whether theabsence of output for a given file meant that it didn’t match anypattern, or that the output hadn’t been generated yet.)

Buffering happens as documented under the GIT_FLUSH option ingit[1]. The caller is responsible for avoiding deadlockscaused by overfilling an input buffer or reading from an empty outputbuffer.

EXIT STATUS

  • 0
  • One or more of the provided paths is ignored.

  • 1

  • None of the provided paths are ignored.

  • 128

  • A fatal error was encountered.

SEE ALSO

gitignore[5]git-config[1]git-ls-files[1]

GIT

Part of the git[1] suite