git check-ignore -v <filepath>

Show why a specific file is ignored by `.gitignore` and which rule causes it.

This command helps you debug why a file is being ignored by Git by showing which ignore rule and file made Git skip it.

This command runs Git’s ignore logic against <filepath> and prints the matching ignore rule, its source file (like .gitignore, .git/info/exclude, or global .gitignore), and the file path, and the -v flag (or --verbose) tells Git to include detailed info about the rule and where it comes from instead of only printing the path; if the file is not ignored, it prints nothing and exits successfully.

You can add more than one <filepath> to check several files at once, combine -v with -n (same as --non-matching) to also show files that are not ignored and the rules that were checked, or drop the verbose flag and just run git check-ignore <filepath> when you only care if the file is ignored without extra details; related commands include git status --ignored to see ignored files in your working tree and inspecting .gitignore files directly to adjust rules once you understand why a file is ignored.

Examples:

  • git check-ignore -v logs/debug.log
  • git check-ignore -v src/.env.local
  • git check-ignore -v build/output.js

Welcome to GitExamples!

Sign in to enable bookmarking, reminders, progress-tracking and more...