Why is a file ignored by global Git rules?

A file can be ignored even when the project .gitignore has no matching rule. Locate the actual source before changing configuration.

1. Identify the matching rule

From the repository root, replace path/to/file with the real path of an untracked file:

git check-ignore -v -- path/to/file

The verbose output names the source file, line number and matching pattern. It can point to a project .gitignore, .git/info/exclude or a global ignore file. A ! pattern re-includes a path. No output can also mean the file is already tracked; check that separately.

2. Locate the configured global ignore file

Inspect the effective core.excludesFile value and the configuration file that defines it:

git config --show-origin --get core.excludesFile

No output with exit status 1 means this setting is absent, not that global ignores are disabled. Git also checks its default ignore file: $XDG_CONFIG_HOME/git/ignore, or $HOME/.config/git/ignore if XDG_CONFIG_HOME is unset or empty. The rule source reported by check-ignore is the best starting point.

3. Change the appropriate source and verify

Use the reported source to decide what to edit. Shared project rules belong in .gitignore; personal rules for one repository belong in .git/info/exclude; personal rules across repositories belong in the global ignore file. Editing a global rule affects other repositories too, so avoid removing the whole configuration to fix one path. Project .gitignore rules take precedence over .git/info/exclude and core.excludesFile. A project exception can override a lower-priority exclusion, provided no parent directory remains excluded. After editing the relevant rule, repeat the check with the actual path:

git check-ignore -v -- path/to/file

Why does ! fail to keep a file inside an ignored directory?

For exact behavior and further details, consult the official references: Git documentation · git check-ignore documentation · Git configuration documentation