Git command to show which specific files are ignored by .gitignore
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
If you want to see which files Git is ignoring, git status --ignored gives a broad view. If you want to know exactly why a specific path is ignored and which ignore rule caused it, git check-ignore -v is the more precise command.
Core Sections
Use git status --ignored for an overview
This command shows ignored files alongside the normal repository status output.
It is useful when you want a quick answer to questions like:
- is this directory being ignored at all
- which ignored files are currently present in the working tree
- is the ignore pattern broader than I expected
The output is good for scanning, but it does not always tell you the exact pattern responsible for each file.
Use git check-ignore -v for the exact rule
When the real question is “which .gitignore entry is causing this file to be ignored,” use:
The -v flag prints the source ignore file, line number, and matching pattern.
That makes it the best debugging command for ignore behavior.
Understand what .gitignore can and cannot do
.gitignore affects untracked files. If a file is already tracked by Git, adding it to .gitignore does not make Git forget it.
For example, if config.local.json is already committed, this ignore rule will not stop Git from noticing changes:
To stop tracking it, remove it from the index first while keeping the file in your working directory.
Then the ignore rule can take effect for future untracked states.
Patterns can come from more than one place
Git ignore behavior does not come only from the repository’s root .gitignore. A file can be ignored because of:
- the root
.gitignore - a nested
.gitignoreinside a subdirectory - '
.git/info/exclude' - the global ignore file configured in Git settings
That is another reason git check-ignore -v is valuable. It tells you which file and line actually matched.
A practical debugging sequence
When a file seems to “disappear” from Git, a reliable sequence is:
- run
git status --ignoredto confirm it is being ignored - run
git check-ignore -v path/to/fileto identify the source rule - check whether the file is already tracked
- adjust the pattern or untrack the file if necessary
That sequence resolves most .gitignore confusion quickly.
Example patterns and exceptions
In this example:
- any
.logfile is ignored - everything under
build/is ignored - '
important.logis re-included if the surrounding directory structure allows it'
This is where the exact-match diagnostic becomes helpful, especially when negation rules interact with broader patterns.
Common Pitfalls
- Using
git statusalone and assuming a missing file is ignored without checking ignored output explicitly. - Forgetting that
.gitignoredoes not affect files Git is already tracking. - Debugging only the repository root
.gitignoreeven though a nested ignore file, exclude file, or global ignore rule may be responsible. - Asking “why is this file ignored” with
git status --ignoredwhengit check-ignore -vis the command that answers that question precisely. - Misreading negation rules such as
!fileand expecting them to work when parent directories are still excluded in a conflicting way.
Summary
- Use
git status --ignoredto see ignored files broadly. - Use
git check-ignore -v pathto see the exact ignore rule and source file. - '
.gitignoreapplies to untracked files, not files already committed to the index.' - Ignore behavior can come from local, nested, repo-specific, or global sources.
- The fastest way to debug ignore issues is to combine broad status inspection with exact rule tracing.

