THE GITHTML FIELD GUIDE
Find which Git ignore rule hides a new file
Use git check-ignore -v with the exact path to identify the ignore file and pattern hiding a new file. Check whether the path is already tracked and whether a parent directory is excluded. Correct the narrowest inappropriate rule; do not force-add the file until you understand whether the exclusion protects secrets, generated output, or another intentional boundary.
Verify the file and the repository first
A missing status entry can have several causes: the file was saved in another directory, belongs to a nested repository, is already unchanged and tracked, or matches an ignore rule. Confirm the actual path and repository root before editing ignore configuration. An editor’s project tree can display files outside the Git root, which makes a path appear mysteriously absent.
If the file is new and real, inspect the exclusion source. Rules can come from .gitignore, repository-local exclusions, or a global excludes file. Two developers with identical source trees can therefore see different untracked files. The source location reported by check-ignore is more useful than adding contradictory patterns until the file appears.
Trace the exact rule
Run from a known location and quote paths containing spaces. The verbose result identifies the matching rule. If no output appears, examine tracking and location rather than assuming the command failed. A tracked path is generally outside normal ignore reporting because ignore rules do not govern its existing tracking.
- If a parent directory is excluded, account for that directory before trying to negate a child-file pattern; a child exception alone may not make traversal possible.
- If a personal global rule is too broad, narrow that rule instead of committing a project exception that only compensates for one developer’s machine.
git rev-parse --show-toplevel
git ls-files -- path/to/new-file
git check-ignore -v -- path/to/new-file
git status --short --ignored --untracked-files=allCorrect the policy before adding content
Read the file before making it visible to staging. A hidden .env file may contain credentials, while a generated cache may simply not belong in history. Force-adding bypasses the rule but does not answer whether publication is appropriate. For legitimate source, correct the relevant exclusion and verify that only the intended new paths become visible.
Then stage the source and any shared policy change explicitly, inspect the patch, and check reproducibility from tracked content. If the problem was a local-only rule, explain that in the troubleshooting note without adding unnecessary repository configuration. The goal is a correct tracking decision, not merely making every local file appear in status.
- If a broad rule hides both generated output and handwritten source in the same directory, test the proposed narrower pattern against representative paths from both groups. Making one wanted file appear is insufficient if the change also exposes hundreds of disposable artifacts to accidental staging.
- When a teammate cannot reproduce the missing-file problem, compare the reported exclusion source rather than exchanging entire configuration files. A personal global pattern or repository-local exclude can explain the difference without changing shared .gitignore rules. Record the exact pattern and affected path in the diagnosis.
Sources and further reading
AI-assisted writing with source-linked guidance and illustrative examples. Read our editorial approach or report a correction.