.gitignore troubleshooting
Find answers to problems with ignore rules and tracked files. Choose the issue that matches what you see.
Why is .gitignore not working?
Use Git commands to find why a file is still tracked, which ignore rule applies, and how negation patterns behave.
How do I ignore files Git already tracks?
Learn why .gitignore does not affect tracked files and how to remove a path from Git’s index while keeping the local copy.
Why does ! fail to keep a file inside an ignored directory?
Fix .gitignore exceptions when a parent directory is excluded. Compare failing and working patterns, then verify which rule matches.
Why is a file ignored by global Git rules?
Find the source of an ignore rule, inspect core.excludesFile and distinguish project, repository-local and global excludes.
How do I ignore folders? folder/ versus /folder/
Choose between root-only and nested directory exclusions, understand trailing slashes and check the matching rule.
How do I ignore file extensions? Using * and **
Compare *.log, /logs/*.log and /logs/**/*.log with concrete paths and recursive matching checks.
How do I ignore files locally without changing .gitignore?
Use the repository-local exclude file for personal untracked files without changing shared project rules.
How do I ignore .env but keep .env.example?
Exclude local environment files, retain a reviewed configuration example and handle environment files already tracked by Git.
How do I ignore .DS_Store in every directory?
Ignore root and nested .DS_Store files, find already tracked copies and remove a specific path from the index.
How do I keep an empty directory? .gitkeep or .gitignore?
Choose a placeholder file or an in-directory .gitignore to preserve a directory while controlling future contents.