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.txtIf the file matches an ignore rule, Git prints which file and which line caused the match:
.gitignore:1:build/ build/output.txtIf 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
BeginnerThe 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.txtOutput shows: file:line:pattern path
.gitignore:1:build/ build/output.txtWithout -v, only matched paths are printed (exit 0 if ignored, 1 if not):
git check-ignore build/output.txtCheck multiple files at once using a wildcard:
git check-ignore *Try it yourself
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Version Control
2Getting Started
Initialize A RepositoryThe .git FolderConfigure Your IdentityGit StatusRecap - First Repo8Merging
What Is A MergeFast-Forward MergeThree-Way MergeMerge ConflictsResolve A ConflictRecap - Merge Master11Feature Branch Project
Project OverviewInitialize Main3Tracking Changes
The Staging AreaGit AddGit CommitModifying A Tracked FileGit LogRecap - First Commits6Recipe Site Project
Project OverviewInitialize And Ignore