git-check-ignore
Check if Git ignores specified files
TLDR
Check whether a file or directory is ignored
Check whether multiple files or directories are ignored
Use pathnames, one per line, from stdin
Do not check the index (used to debug why paths were tracked and not ignored)
Include details about the matching pattern for each path
SYNOPSIS
git check-ignore [-q|--quiet] [-v|--verbose] [-c|--class] [--no-index] [--stdin] [-z|--null] [--] <pathspec>…
PARAMETERS
-q, --quiet
Suppress output; exit 1 if any path ignored, 0 otherwise.
-v, --verbose
Output the ignore rule: path, pattern, source file, line number.
-c, --class
Output the rule class (e.g., !!, .gitignore, exclude).
--no-index
Ignore index state; check as if all paths untracked.
--stdin
Read paths from stdin instead of arguments.
-z, --null
Paths terminated by NUL (use with --stdin or args).
DESCRIPTION
git check-ignore is a Git utility for debugging ignore rules. It determines if specified paths match any ignore patterns from .gitignore files (in the working tree and subdirectories), .git/info/exclude, or global excludes via core.excludesfile. By default, it simulates the check Git performs before adding files to the index, respecting tracked status unless --no-index is used.
If a path is ignored, the command prints it (unless -q). With -v, it also shows the matching pattern, source file, and line number. -c adds the rule's class (e.g., !! for exceptions). Exit status is 0 if any path is not ignored, 1 if all are ignored, and >1 on error. Ideal for scripts and troubleshooting why files aren't tracked.
Supports multiple paths, stdin input (--stdin), and NUL-delimited strings (-z) for safe parsing.
CAVEATS
Does not verify path existence or stage status; only simulates ignore check. Paths relative to current directory.
EXIT STATUS
0: At least one path not ignored.
1: All paths ignored.
>1: Usage or other error.
EXAMPLE
git check-ignore -v Makefile
Makefile
*.mk config.mk:1
HISTORY
Introduced in Git 1.7.6 (April 2011) to simplify debugging complex ignore rules across projects.
SEE ALSO
git-status(1), git-add(1), gitignore(5), git-config(1)


