Skip to content

check-ignore Git Command Guide

The git check-ignore command is used to debug .gitignore and exclude files by checking whether given pathnames are excluded by .gitignore rules or other exclude mechanisms. It helps understand why certain files are being ignored or tracked unexpectedly.

Terminal window
git check-ignore [<options>] <pathname>...
Terminal window
git check-ignore [<options>] --stdin
OptionDescription
-q, —quietDon’t output anything, just set exit status
-v, —verboseInstead of printing excluded paths, print the matching exclude pattern with the path
—stdinRead pathnames from the standard input, one per line
-zThe output format is modified to be machine-parsable
-n, —non-matchingShow given paths which don’t match any pattern
—no-indexDon’t look in the index when undertaking the checks
ParameterDescription
File path(s) to check for ignore status
Terminal window
git check-ignore temp.log

Outputs the path if it matches an ignore pattern, no output if not ignored.

Terminal window
git check-ignore file1.txt file2.log build/

Shows which of the given paths are excluded by ignore rules.

Terminal window
git check-ignore -v *.tmp

Displays the specific ignore pattern that matches, along with the path.

Terminal window
echo "cache/" | git check-ignore --stdin

Reads pathnames from standard input instead of command line.

Terminal window
git check-ignore -v -n important.md *.log

Shows both matching and non-matching patterns with details.

Terminal window
git check-ignore --no-index *.o

Checks ignore status without considering tracked files in the index.

How do I check if a file is ignored by git?

Section titled “How do I check if a file is ignored by git?”

To check if a file is ignored by git, use:

Terminal window
git check-ignore <path>

How can I see which pattern is ignoring a file?

Section titled “How can I see which pattern is ignoring a file?”

To see which pattern is ignoring a file, run:

Terminal window
git check-ignore -v <path>

To check multiple files at once, execute:

Terminal window
git check-ignore <path1> <path2>...

How can I use stdin to check ignore status?

Section titled “How can I use stdin to check ignore status?”

To use stdin to check ignore status, use:

Terminal window
echo "<path>" | git check-ignore --stdin

To see non-matching paths, run:

Terminal window
git check-ignore -n -v <path>

How can I debug ignoring logic without index?

Section titled “How can I debug ignoring logic without index?”

To debug ignoring logic without the index, use:

Terminal window
git check-ignore --no-index <path>

Applications of the git check-ignore command

Section titled “Applications of the git check-ignore command”
  1. Debugging why certain files are unexpectedly ignored or tracked
  2. Validating .gitignore patterns before committing
  3. Checking ignore status during automated build processes
  4. Troubleshooting conflicting ignore rules across multiple files
  5. Analyzing ignore patterns for repository maintenance
  6. Educating team members on ignore rule application
  7. Testing new ignore patterns before adding them to .gitignore