Keep Your Branch in Sync
The One Rule You Must Follow
The rule is simple: rebase before you push, merge after you push.
Why it matters
When you rebase, Git deletes your original commits and creates new ones with new IDs. This is fine when those commits only live on your machine. But once they're on the remote, your teammates can see them and build on top of them. Rewriting them pulls the floor out from under everyone else.
The safe zone - before pushing
You're working on feature/login locally. main has moved forward while you were working:
Safe to Rebase: Local Commits
Nobody has seen C and D yet. You can rebase freely:
git rebase main
Your commits get replayed on top of E:
Rebased and Ready to Push
Clean, linear, no problem. Now you push.
The danger zone - after pushing
You pushed feature/login. Your teammate pulled it and added their own commit F:
A Teammate Builds on Your Branch
Now you rebase again:
# rewrites C' and D' into C'' and D''
git rebase main
# Git rejects this - histories don't match anymore
git push origin feature/login
# you force it through
git push --force origin feature/login
Learn Git in a Day - The Visual Guide
Everything you need, nothing you don'tEnroll now to unlock all content and receive all future updates for free.



