Menu
CoddyTech

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 has a .gitignore containing *.log and two files: readme.md and error.log.

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

Every run starts from a fresh copy of the folder, which is not a Git repository yet. The editor starts with git init -q -b main for you. Keep that line: git check-ignore only works inside a repository, and without it you will see fatal: not a git repository.

Try it yourself

Terminal
git init -q -b main
# Your commands below
quiz iconTest yourself

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

All lessons in Version Control

Practice on your own: Terminal playground