The Plain Picture#
Some things should never be in a shared photo album: your bank PIN, a photo of your passport, or a 50 GB video that makes the album impossible to carry.
The Real Names#
.gitignoreis a file listing patterns of files Git should never track.Secrets — passwords, API keys, private keys,
.envfiles (The Linux Command Line Ch 8) — must never be committed.Git LFS (Large File Storage) stores big binary files (videos, datasets, model weights) outside the normal repository, keeping only small pointers in Git.
Under the Hood#
A typical .gitignore for StudyBuddy:
# secrets
.env
*.pem
# Python
__pycache__/
*.pyc
venv/
.venv/
# JavaScript
node_modules/
dist/
.next/
# OS / editor junk
.DS_Store
.idea/
.vscode/.gitignore only affects untracked files. If a file is already tracked, adding it to .gitignore does nothing — you
must also stop tracking it: git rm --cached .env (removes it from Git, keeps it on disk).
If you commit a secret#
Because every commit is in the history (Ch 3), deleting the file in a new commit does not remove the secret — it's still in the old commit, and in every clone. Bots scan GitHub for leaked keys continuously and can use them within minutes.
The correct order:
Revoke / rotate the secret immediately — create a new API key and disable the old one. This is the step that actually protects you. Assume the old one is compromised.
Remove it from history with a tool like
git filter-repo(or BFG), then force-push — and every teammate must re-clone. This is cleanup, not protection.Prevent it next time:
.gitignore, and a secret scanner (GitHub secret scanning,gitleaks) in pre-commit hooks and CI.
Gotchas
Why not commit
node_modules/orvenv/? They're huge, machine-specific, and fully reproducible frompackage.json/requirements.txt(Python Packaging and Tools (coming soon)).Large files bloat the repo forever, even after deletion, because history keeps them. Use LFS or external storage from the start.
Check yourself
3 questionsYou add .env to .gitignore, but Git still shows it as modified. Why, and how do you fix it?
Show answerHide answer
It's already tracked; .gitignore only affects untracked files. Run git rm --cached .env and commit.
You pushed an API key to GitHub. What's the first thing you do?
Show answerHide answer
Revoke/rotate the key immediately.
Why doesn't deleting the file in a new commit solve the leak?
Show answerHide answer
The key is still in the earlier commit in the history, and in every clone.