gitignore · git stash · git rebase
Beyond fork · clone · branch · commit · push
Most people learn how to make commits. Almost no one learns how to keep a repository and its history clean.
Three small habits do most of the work:
Prevent the mess. Stop junk from ever entering the repo.
Avoid the mess. Set work aside without a junk commit.
Fix the mess. Rewrite messy commits into clean ones.
Prevent it, avoid it, or fix it, and your history stays readable.
.gitignorePrevent the mess
A plain text file that tells Git which files to never track. You commit code, not the things around it:
*.csv, *.parquet, raw datasets.env files, API keys_site/, __pycache__/A leaked key or a 2 GB file buried in history is painful to undo. Prevention always beats cleanup.
git stashAvoid the mess
You’re mid-edit when something urgent pulls you to another branch. Your changes aren’t ready to commit. What now?
git rebase -iFix the mess
Real working history is honest, and honestly ugly:
No reviewer wants to read “oops” and “WIP”. Interactive rebase lets you rewrite these before anyone sees them:
Fix the mess
Four noisy commits become one you’d be proud to ship:
Warning
Golden rule: rebase only commits you haven’t shared yet. Rewrite local history freely, but never rewrite main.
A clean history is a gift to your reviewer, and to future you.