You know the feeling. You’re three commits deep, something broke, and now your git log looks like a conspiracy theory. Breathe.
You don’t need AI to fix your Git mess. You need a boring, repeatable workflow. Let’s build one.
1. The Golden Rule: One Thing at a Time
Never mix a bug fix with a new feature. Never mix formatting changes with logic changes.
Why?
When you revert, you’ll lose both. When you review, you’ll hate yourself.
Fix:
Make small, atomic commits. If you catch yourself writing “and” in a commit message:
"fix login bug and update README"
Stop. Split it.
2. The Basic Sanity Workflow (Solo Devs / Small Teams)
This works for 90% of daily work.
# Start from a clean main
git checkout main
git pull origin main
# Create a feature branch
git checkout -b feature/short-description
# Do your work, commit often
git add .
git commit -m "add: specific change"
# Rebase before merging (clean history)
git checkout main
git pull origin main
git checkout feature/short-description
git rebase main
# Fast-forward merge
git checkout main
git merge --ff-only feature/short-description
git push origin main
Why rebase?
It avoids messy “merge bubbles” and keeps history clean and linear.
3. The “Oh No, I Committed to Main” Escape
We’ve all done it.
If you haven’t pushed:
git reset HEAD~1 --soft
If you already pushed (and no one else pulled):
git reset HEAD~1 --hard
git push --force-with-lease
Pro tip:
--force-with-lease > --force (safer, won’t overwrite others’ work).
4. Fix a Typo in the Last Commit
No need for "oops typo" commits.
git add fixed-file.js
git commit --amend --no-edit
If already pushed:
git push --force-with-lease
(Only if you're the only one using that branch.)
5. Branch Naming That Doesn’t Suck
Keep it consistent and readable:
feature/add-payment
bugfix/fix-login-null
hotfix/update-ssl-cert
chore/update-deps
docs/api-authentication
Prefixes:
-
feature/– new functionality -
bugfix/– non-urgent fixes -
hotfix/– production issues -
chore/– tooling/config -
docs/– documentation
6. Undo Almost Anything with reflog
Git quietly tracks everything.
git reflog
git reset <commit-hash> --hard
Think of it as Ctrl + Z for Git.
7. Pull Request Workflow (Teams)
main
└── develop
└── feature/xyz
Rules:
- Don’t push directly to
mainordevelop - PR:
feature → develop - Merge with
--no-ff - Periodically merge
develop → mainfor releases
8. One Alias That Actually Helps
Add this to ~/.gitconfig:
[alias]
tree = log --graph --pretty=oneline --abbrev-commit --all
unstage = reset HEAD --
last = log -1 HEAD
co = checkout
br = branch
st = status
Now run:
git tree
…and enjoy a clean visual history.
When to Break These Rules
Hotfix in production?
Commit directly tomain(but communicate it).Tiny doc fix?
Fine to commit directly if you’re solo. Use[ci skip].Solo dev life?
Do what you want—but build good habits anyway.
Final Thought
Git isn’t about knowing 100 commands.
It’s about knowing a few commands really well and following a predictable workflow.
Stop fighting your version control. Copy this, tweak it for your team, and get back to shipping.
— A dev who has lost code exactly twice and learned both times
Top comments (2)
Hey!! Great article!!!
Really appreciate you reading it !