By admin , 29 April 2026

Why a good .gitignore matters

Every accidentally committed node_modules, .env, or compiled binary is technical debt. A complete .gitignore from day one prevents the problem entirely. GitHub's github/gitignore repo provides community-maintained templates - the snippets below adapt them for common stacks.

Node.js

# Dependencies
node_modules/
.pnp
.pnp.js

# Build output
dist/
build/
out/
.next/
.nuxt/
.vite/

# Logs
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*

# Environment
.env
.env.local
.env.*.local

# Editor
.vscode/
.idea/
*.swp

# Coverage
coverage/
.nyc_output/

Python

# Byte-compiled
__pycache__/
*.py[cod]
*$py.class

# Packaging
*.egg-info/
*.egg
build/
dist/
pip-wheel-metadata/

# Virtual envs
.venv/
venv/
env/
ENV/

# Tools
.pytest_cache/
.mypy_cache/
.ruff_cache/
.tox/
.coverage
htmlcov/

# Jupyter
.ipynb_checkpoints/

# Editor
.idea/
.vscode/

# Environment
.env

Rust

# Build output
target/
Cargo.lock        # commit for binaries, ignore for libraries

# Binaries
*.exe
*.dll
*.so
*.dylib

# Fuzzing
artifacts/
corpus/

# IDE
.idea/
.vscode/
*.iml

Convention: commit Cargo.lock for application crates (reproducible builds); ignore for library crates (downstream chooses versions).

PHP / Composer

vendor/
composer.phar

# Cache
.phpunit.result.cache
.php-cs-fixer.cache
.phpstan-cache/

# Symfony / Laravel
/var/cache/*
/var/log/*
/public/uploads/
.env
.env.local

# IDE
.idea/
.vscode/
*.iml

Java / Gradle / Maven

# Compiled
*.class
*.jar
*.war
*.ear

# Maven
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup

# Gradle
.gradle/
build/
!gradle/wrapper/gradle-wrapper.jar

# IDE
.idea/
*.iml
.classpath
.project
.settings/
.vscode/

# Logs
*.log

Cross-cutting essentials

Every .gitignore should include OS- and editor-specific noise:

# OS
.DS_Store
Thumbs.db
desktop.ini

# Editors
*.swp
*.bak
*~
.vscode/
.idea/

# Secrets
*.pem
*.key
.env*
!.env.example

Global gitignore

OS and editor files belong in your global gitignore, not per-project:

git config --global core.excludesfile ~/.gitignore_global
cat > ~/.gitignore_global <<'EOF'
.DS_Store
*.swp
.vscode/
.idea/
EOF

Generating from templates

# Use gitignore.io
curl -sL https://www.toptal.com/developers/gitignore/api/node,python,visualstudiocode,macos > .gitignore

This composes templates and produces a tailored .gitignore for any combination of languages and tools.

Auditing

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

Verify that ignored files are recognised and that nothing important is silently excluded.