Git Reference ยท Plumbing Commands
git check-ignore command
Reference for git check-ignore: find out whether a path is ignored, which pattern and file matched with -v, test with --no-index, and read the exit codes.
git check-ignore answers the question "is this path ignored, and why?". Given one or more paths, it prints those that are ignored. With -v it also shows the file, line number and pattern responsible, which makes it the first tool to reach for when a file refuses to be added or an unexpected file is hidden.
The command evaluates all the sources Git uses: .gitignore files in the tree, .git/info/exclude and the global file named by core.excludesFile.
git check-ignore build/app.o
git check-ignore -v build/app.o
Try it
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Syntax
git check-ignore [<options>] <pathname>... git check-ignore [<options>] --stdin
| Name | Description |
|---|---|
<pathname>... |
Paths to test, relative to the current directory. They do not have to exist. |
-v, --verbose |
Print <source>:<linenum>:<pattern><TAB><pathname> for each match. |
-n, --non-matching |
With -v, also show paths that match nothing (the source and pattern columns are empty). |
--no-index |
Ignore the index: report matching rules even for tracked files. |
--stdin |
Read paths from standard input, one per line. |
-z |
Use NUL as separator for input and output. |
-q, --quiet |
Print nothing; use only the exit code. Allowed with exactly one path. |
Returns: the ignored paths (or the verbose form).
Exit codes: 0 if at least one path is ignored, 1 if none is ignored, 128 for a fatal error.
Usage notes
- Tracked files are skipped. A file already in the index is never "ignored" in practice, so
check-ignoreprints nothing for it unless you pass--no-index. This is the usual reason a pattern "does not work": the file was committed earlier. Remove it withgit rm --cached. - Negation is shown. A matching negated pattern (
!keep.log) appears in-voutput with the leading!, so you can see the file is explicitly un-ignored. Without-vit is not printed. - Directories: a pattern ending in
/only matches directories, so testbuild/or a path inside it, not a file namedbuild. - Last match wins within one source, and files closer to the path override those further away.
-vreports the deciding line. - Not for untracked listing. To see all ignored files use
git status --ignoredorgit ls-files -o -i --exclude-standard. - Case: matching follows
core.ignoreCase(seecore.ignoreCase).