Click any section to expand the patterns and templates.
π Pattern Syntax
How .gitignore patterns work basics
# Comment *.log # Ignore all .log files /dist # Ignore dist in root only (not subdirs) dist/ # Ignore any directory named dist build/ # Ignore any directory named build !important.log # Don't ignore this specific file **/logs # Match "logs" at any depth src/**/*.test.js # Match test files under src/Key rules:
*matches anything except/**matches any number of directories- Trailing
/means "directories only" - Leading
/means "root of repo only" !negates a pattern (un-ignores)
Already tracked? git rm --cached gotcha
.gitignore doesn't remove it if it's already tracked.
# Stop tracking a file (keep it locally) git rm --cached secret.envStop tracking a whole folder
git rm -r βcached node_modules/
Then commit
git add .gitignore git commit -m βRemove tracked files that should be ignoredβ
π’ Node.js / JavaScript
Node.js .gitignore template
node_modules/ dist/ build/ .next/ .nuxt/ .output/ .cache/ coverage/Environment
.env .env.local .env.*.local
Logs
npm-debug.log* yarn-debug.log* yarn-error.log* pnpm-debug.log*
OS
.DS_Store Thumbs.db
IDE
.vscode/ .idea/ *.swp *.swo
π Python
Python .gitignore template
# Virtual environments venv/ .venv/ env/ .env/Byte-compiled
pycache/ *.py[cod] *$py.class *.pyo
Distribution
dist/ build/ *.egg-info/ *.egg
Testing
.pytest_cache/ .coverage htmlcov/ .tox/ .mypy_cache/
Jupyter
.ipynb_checkpoints/
Environment
.env *.env
OS / IDE
.DS_Store .idea/ .vscode/ *.swp
β Java / Kotlin
Java / Maven / Gradle .gitignore template
# Compiled *.class *.jar *.war *.earMaven
target/
Gradle
.gradle/ build/ !gradle/wrapper/gradle-wrapper.jar
IDE
.idea/ *.iml .project .classpath .settings/ bin/
OS
.DS_Store Thumbs.db
π¦ Rust
Rust .gitignore template
# Build output /target/ **/*.rs.bkFor libraries, uncomment theCargo.lock β include for binaries, ignore for libraries
Cargo.lock
OS / IDE
.DS_Store .idea/ .vscode/ *.swp
Cargo.lock line. For binaries and applications, keep it tracked.
πΉ Go
Go .gitignore template
# Binary output /bin/ *.exe *.exe~ *.dll *.so *.dylibGo modules (Test
*.test *.out coverage.txt
Vendor (if not committing)
vendor/
OS / IDE
.DS_Store .idea/ .vscode/ *.swp
go.mod and go.sum) should always be committed.
π Universal Patterns
Environment & secrets security
# Environment files .env .env.* !.env.exampleCreate aSecrets
*.pem *.key *.p12 *.pfx *.keystore
AWS
.aws/credentials
Terraform
*.tfvars .terraform/
.env.example with placeholder values so other developers know what variables are needed.
OS files universal
# macOS .DS_Store .AppleDouble .LSOverride ._*Pro tip: Add these to your global gitignore so you donβt need them in every repo:Windows
Thumbs.db ehthumbs.db Desktop.ini $RECYCLE.BIN/
Linux
*~ .directory
git config --global core.excludesfile ~/.gitignore_global
IDE / editor files universal
# VS Code .vscode/ !.vscode/settings.json !.vscode/extensions.jsonLike OS files, these are better in your global gitignore.JetBrains (IntelliJ, WebStorm, PyCharm)
.idea/ *.iml
Vim
*.swp *.swo *~ .netrwhist
Emacs
~ ## .#*