Git 2 reference · Investigating and Tools

git check-ignore Command (Git)

Find out whether a path is ignored and which .gitignore rule ignores it; useful for debugging .gitignore patterns.

Git 2

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

git check-ignore [-v] PATH...

Parameters

ParameterDescription
-v Show the source file, line and pattern.
--no-index Check even tracked files.

Examples

Which rule matches
git init -q -b main app && cd app
echo '# Shop' > README.md
git add README.md && git commit -q -m 'Initial commit'
printf 'node_modules/\n*.log\n!keep.log\n' > .gitignore
mkdir node_modules; touch app.log keep.log
git check-ignore -v node_modules/x app.log keep.log || true

Output

.gitignore:1:node_modules/	node_modules/x
.gitignore:2:*.log	app.log
.gitignore:3:!keep.log	keep.log

Run this on your computer — see “Get Started” for setup.

Ignored files don't show in status
git init -q -b main app && cd app
echo '# Shop' > README.md
git add README.md && git commit -q -m 'Initial commit'
echo 'build/' > .gitignore; mkdir build; touch build/a.o
git status -s

Output

?? .gitignore

Run this on your computer — see “Get Started” for setup.

Was this page helpful?