Menu
Coddy logo textTech

Check Ignore Rules

Part of the Version Control section of Coddy's Terminal journey — lesson 21 of 58.

When a file unexpectedly does (or does not) show up in git status, it can be hard to tell which rule is responsible. Git provides a tool just for this:

git check-ignore -v build/output.txt

If the file matches an ignore rule, Git prints which file and which line caused the match:

.gitignore:1:build/    build/output.txt

If you want a yes/no answer for one path, omit the -v flag. Git exits with status 0 if the file is ignored and 1 if it is not, and prints the path only when matched.

For a quick listing of "all matched files", you can use:

git check-ignore *

This is invaluable for debugging tricky .gitignore configurations on real projects.

challenge icon

Challenge

Beginner

The folder is already a Git repo with a .gitignore containing *.log. Two files exist: readme.md and error.log.

Run git check-ignore on both files at once and print only the matched paths.

Cheat sheet

Use git check-ignore -v to debug which .gitignore rule matches a file:

git check-ignore -v build/output.txt

Output shows: file:line:pattern path

.gitignore:1:build/    build/output.txt

Without -v, only matched paths are printed (exit 0 if ignored, 1 if not):

git check-ignore build/output.txt

Check multiple files at once using a wildcard:

git check-ignore *

Try it yourself

Terminal
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Version Control