1. Check whether Git already tracks the file
Ignore rules apply to intentionally untracked files. If the file was committed earlier, adding a pattern will not remove it from Git’s index.
git ls-files -- path/to/fileIf this prints the path, the file is tracked. Follow the tracked-file guide:
2. Ask Git which rule matched
Run the checker from your repository, using the actual path relative to that repository. The output points to the source ignore file and line.
git check-ignore -v -- path/to/fileUse --no-index when testing a file that is already tracked:
git check-ignore -v --no-index -- path/to/file 3. Review pattern location and order
A leading slash anchors a pattern to the directory containing that .gitignore file. A trailing slash restricts it to directories. Later matching patterns at the same precedence level can override earlier ones. A pattern beginning with ! can re-include a path, but not a file inside a directory Git has already excluded from traversal.
4. Check other ignore sources
Git also reads .git/info/exclude and the global file configured with core.excludesFile. A file may therefore be hidden even when your project’s .gitignore does not mention it. Check the global configuration with:
git config --get core.excludesFile For exact behavior and further details, consult the official references: Git documentation