.gitignore Cheatsheet - Ignore Patterns & Rules
The glob syntax and pitfalls you forget when writing .gitignore, grouped by wildcards, directories, negation and global config, with copy-ready examples.
Back to Version ControlBasic Syntax 6
*.logIgnore all .log files
build/Ignore the build directory and its contents
/distIgnore dist only at repo root (not subdirs)
**/node_modulesIgnore node_modules at any depth
doc/*.txtIgnore .txt one level under doc (not nested)
!keep.txtNegation: do NOT ignore keep.txt
Wildcards & Comments 6
?Match a single character
[abc]Match any char in brackets
**Match any number of directories
# noteComment line
#fileEscape # to match a literal hash
!impEscape ! to match a literal bang
Dirs & Files 4
.cacheIgnore a file or dir named .cache
*.tmpIgnore all temp files
logs/*.logIgnore logs one level deep
*.swpIgnore editor swap files
Global & Effects 4
git config --global core.excludesfile ~/.gitignore_globalSet a global ignore file
git check-ignore -v fileShow which rule ignores a file
git rm --cached fileStop tracking but keep the local file
git add -f fileForce-add an ignored file
Common Language Templates 4
node_modules/Node dependencies dir
.envEnv vars (secrets, always ignore)
__pycache__/Python cache
.DS_StoremacOS system file
💡 Tips
- Patterns are relative to the .gitignore location; use /dist to anchor at root.
- A negation !file only works if its parent directory is not ignored.
- Use git check-ignore -v file to see which rule ignores a file.
- For already-tracked files, git rm --cached stops tracking but keeps the file.
Official References
Commands are compiled from the official docs below. Click to verify the latest usage.
Maintained by LaoHand
Publicly updated on Aug 2, 2026, continuously proofread against official docs.
Found an error? Report it
Wrong command or description? Open an issue to help us fix it.
Found an error? Report it