Contents
What is .gitignore
A .gitignore file tells Git which files to ignore — don't track, don't include in commits. Created at the repo root.
What must always be ignored
Dependencies — node_modules, vendor, .venv. Generated automatically by npm install, weighing hundreds of MB, different on every machine.
Environment files — .env. Contains secrets: passwords, API keys, tokens. Commit it once and they're in your public repo (how to pass them into containers safely is in the Docker Compose article).
⚠️ If you already committed
.env— just adding it to .gitignore won't help. You need to remove the file from history and rotate all compromised keys.
System files — .DS_Store (macOS), Thumbs.db (Windows).
Build artifacts — dist/, build/, .next/, __pycache__/.
How to organize the branches and commits themselves is covered in Git flow.
Typical .gitignore for Node.js
# Dependencies
node_modules/
# Environment
.env
.env.local
.env.*.local
# Build
dist/
build/
.next/
# Logs
*.log
npm-debug.log*
# System
.DS_Store
Thumbs.db
# Editors
.vscode/settings.json
.idea/
💡 The site gitignore.io generates a ready
.gitignoreby technology. Type "Node", "Python", "macOS" — you get a full file.
Global .gitignore
System junk is better off in a global gitignore — instead of adding it to every project:
touch ~/.gitignore_global
git config --global core.excludesfile ~/.gitignore_global
echo ".DS_Store" >> ~/.gitignore_global
echo ".idea/" >> ~/.gitignore_global
If a file is already in the repo
Adding it to .gitignore doesn't remove an already-tracked file. To untrack it but keep it locally:
git rm -r --cached node_modules/
git rm --cached .env
git commit -m "remove tracked files from gitignore"
Discussion
No comments yet. Be the first.