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
Syntax
git check-ignore [-v] PATH...
Parameters
| Parameter | Description |
|---|---|
-v |
Show the source file, line and pattern. |
--no-index |
Check even tracked files. |
Examples
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.
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.
Related
git clean· Remove untracked files from the working tree; always preview with -n first.git status· Show which files are staged, modified or untracked, and how the branch relates to its upstream.- Ignoring Files with .gitignore · tutorial