How can I find out which Git ignore rule matches a file?
Quick answer
From inside the repository, run git check-ignore -v -- path/to/file. Git reports the matching pattern and where it came from, including a per-directory exclude file, .git/info/exclude, or the file configured by core.excludesFile. If the file is tracked, the default check does not report it; add --no-index to check tracked files too. No match means these rules do not ignore that path.
The question, the details, the next step.
A practical checklist
Run
git check-ignore -v -- [path]from inside the repository.Record the reported pattern, source file, and line number.
If there is no result, determine whether the path is tracked.
For a tracked path, rerun the check with
--no-index.Use
-nwith-vif you want non-matching paths shown.
A few more useful answers
What does the source path in verbose output tell me?
It identifies where Git found the matching rule, such as a per-directory exclude file, .git/info/exclude, or the configured core.excludesFile. The configured excludes file is shown with an absolute path. [S1]
Does no output prove that no ignore rule can ever apply to this file?
It means no matching rule was reported for the checked path under that check. Tracked files are omitted by default, so check those with --no-index; -n with -v can show a non-match. [S1]
Sources
References used for this guide.
- [S1] Git check-ignore documentation: identify matching ignore rules git-scm.com · Checked
