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.
git check-ignore Syntax:
Section titled “git check-ignore Syntax:”git check-ignore [<options>] <pathname>...git check-ignore [<options>] --stdinOptions:
Section titled “Options:”| Option | Description |
|---|---|
| -q, —quiet | Don’t output anything, just set exit status |
| -v, —verbose | Instead of printing excluded paths, print the matching exclude pattern with the path |
| —stdin | Read pathnames from the standard input, one per line |
| -z | The output format is modified to be machine-parsable |
| -n, —non-matching | Show given paths which don’t match any pattern |
| —no-index | Don’t look in the index when undertaking the checks |
Parameters:
Section titled “Parameters:”| Parameter | Description |
|---|---|
| File path(s) to check for ignore status |
git check-ignore Command Samples:
Section titled “git check-ignore Command Samples:”Check if a file is ignored
Section titled “Check if a file is ignored”git check-ignore temp.logOutputs the path if it matches an ignore pattern, no output if not ignored.
Check multiple files
Section titled “Check multiple files”git check-ignore file1.txt file2.log build/Shows which of the given paths are excluded by ignore rules.
Show matching pattern details
Section titled “Show matching pattern details”git check-ignore -v *.tmpDisplays the specific ignore pattern that matches, along with the path.
Use stdin for input
Section titled “Use stdin for input”echo "cache/" | git check-ignore --stdinReads pathnames from standard input instead of command line.
Show non-matching paths
Section titled “Show non-matching paths”git check-ignore -v -n important.md *.logShows both matching and non-matching patterns with details.
Check ignoring index state
Section titled “Check ignoring index state”git check-ignore --no-index *.oChecks 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:
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:
git check-ignore -v <path>How do I check multiple files at once?
Section titled “How do I check multiple files at once?”To check multiple files at once, execute:
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:
echo "<path>" | git check-ignore --stdinHow do I see non-matching paths?
Section titled “How do I see non-matching paths?”To see non-matching paths, run:
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:
git check-ignore --no-index <path>Applications of the git check-ignore command
Section titled “Applications of the git check-ignore command”- Debugging why certain files are unexpectedly ignored or tracked
- Validating .gitignore patterns before committing
- Checking ignore status during automated build processes
- Troubleshooting conflicting ignore rules across multiple files
- Analyzing ignore patterns for repository maintenance
- Educating team members on ignore rule application
- Testing new ignore patterns before adding them to .gitignore