πŸ“‹ Cheat Sheets

.gitignore Cheat Sheet β€” Templates for Every Project


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
Adding a file to .gitignore doesn't remove it if it's already tracked.
# Stop tracking a file (keep it locally)
git rm --cached secret.env

Stop 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
*.ear

Maven

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.bk

Cargo.lock β€” include for binaries, ignore for libraries

Cargo.lock

OS / IDE

.DS_Store .idea/ .vscode/ *.swp

For libraries, uncomment the Cargo.lock line. For binaries and applications, keep it tracked.

🐹 Go

Go .gitignore template
# Binary output
/bin/
*.exe
*.exe~
*.dll
*.so
*.dylib

Test

*.test *.out coverage.txt

Vendor (if not committing)

vendor/

OS / IDE

.DS_Store .idea/ .vscode/ *.swp

Go modules (go.mod and go.sum) should always be committed.

🌐 Universal Patterns

Environment & secrets security
Always ignore these. No exceptions.
# Environment files
.env
.env.*
!.env.example

Secrets

*.pem *.key *.p12 *.pfx *.keystore

AWS

.aws/credentials

Terraform

*.tfvars .terraform/

Create a .env.example with placeholder values so other developers know what variables are needed.

OS files universal
# macOS
.DS_Store
.AppleDouble
.LSOverride
._*

Windows

Thumbs.db ehthumbs.db Desktop.ini $RECYCLE.BIN/

Linux

*~ .directory

Pro tip: Add these to your global gitignore so you don’t need them in every repo:

git config --global core.excludesfile ~/.gitignore_global
IDE / editor files universal
# VS Code
.vscode/
!.vscode/settings.json
!.vscode/extensions.json

JetBrains (IntelliJ, WebStorm, PyCharm)

.idea/ *.iml

Vim

*.swp *.swo *~ .netrwhist

Emacs

~ ## .#*

Like OS files, these are better in your global gitignore.