git-check-ignore
Debug gitignore patterns and ignored files
TLDR
Check if file is ignored
SYNOPSIS
git check-ignore [options] pathspec
DESCRIPTION
git check-ignore debugs gitignore patterns. It reports whether paths are ignored and which pattern causes the ignore, helping troubleshoot gitignore rules.
The verbose mode (-v) shows the gitignore file, line number, and pattern responsible for ignoring a path. This is essential for debugging complex gitignore configurations with multiple .gitignore files at different directory levels.
The --non-matching option combined with -v can also show why a file is not being ignored, helping diagnose cases where files unexpectedly appear in git status output.
PARAMETERS
PATHSPEC
File paths to check.-v, --verbose
Show source and pattern.--stdin
Read paths from stdin.-z
NUL-terminate output.-n, --non-matching
Show non-matching paths.-q, --quiet
Exit with status only.--help
Display help information.
CONFIGURATION
.gitignore
Pattern list specifying intentionally untracked files to ignore. Multiple .gitignore files can exist at different directory levels.~/.config/git/ignore
User-level global ignore patterns applied to all repositories./etc/gitconfig
System-wide core.excludesFile configuration pointing to global ignore file.
CAVEATS
Only checks patterns, not actual files. Nested gitignore files have priority. Negation patterns can override ignores.
HISTORY
git check-ignore was added to Git to help debug gitignore rules, addressing common frustration with ignore pattern behavior.
SEE ALSO
git-status(1), gitignore(5)
