Git Hygiene: Small Commits, Clear Messages, No Drama
Good git hygiene isn’t about following rules. It’s about making your life easier.
Small Commits
One logical change per commit.
Why?
- Easy to review
- Easy to revert
- Easy to cherry-pick
- Easy to understand in git log
Bad:
git commit -m "misc fixes"
Good:
git commit -m "[fix]: handle null user state"
git commit -m "[refactor]: extract validation logic"
git commit -m "[feature]: add email notifications"
Clear Messages
Format: [type]: description
Types:
[fix]- bug fixes[feature]- new functionality[refactor]- code cleanup[perf]- performance improvements[docs]- documentation
Rebase Before Push
Always rebase (or merge) before pushing:
git fetch origin
git rebase origin/master
git push origin branch-name
Why? Prevents merge conflicts on PR creation. Keeps history clean.
The Build Check
Before every PR:
pnpm -r build # or npm run build, etc.
If it builds locally, it (probably) builds in CI.
Saves embarrassing “CI failed” notifications.
Branch Cleanup
After PR merged:
git checkout master
git pull origin master
git branch -D old-branch-name
Don’t let dead branches pile up.
Why This Matters
Git history is documentation. Future you (or your teammates) will read it.
Make it readable.