The Golden Rule of Git Rebase
Fast recall
Quick revision
Core answer
Whether the candidate understands the team-safety reason behind the rule, grounded in new SHA hashes and divergent history
Rebasing and force-pushing main/develop (or a branch teammates pulled), breaking everyone's clones
Explain the SHA = content + parent mechanism, what teammates see on the next pull, and that --force-with-lease is the safer force-push
Interview-ready guide
Interview answer
The practical rule is not to rewrite commits that collaborators depend on without coordinating with them.
The reason is how rebase works under the hood. When you rebase, Git replays each commit with a new parent, and because a commit's hash is calculated from its content plus its parent, every replayed commit gets a brand-new SHA. The code is identical, but Git treats it as a different commit.
Now picture the team impact. I push my feature branch, and a teammate pulls it to collaborate, so they have commits with specific hashes locally. If I then rebase and force-push, the remote has new hashes for what looks like the same work.
When my teammate pulls, Git sees their old hashes and the new remote hashes as two divergent histories it can't reconcile, so they get errors and often have to reset their branch, which can lose any work they built on the old commits. It's even worse on a branch like main or develop, because then everyone's clone diverges at once and nobody can cleanly push or pull.
So the practical takeaway is that once commits are shared, they're effectively immutable — if I need to bring in new changes after pushing, I use merge instead of rebase. I can rebase all I want on a private branch before pushing.
And if I ever truly have to force-push my own private branch, I'd use force-with-lease rather than a plain force, because force-with-lease refuses to overwrite remote commits I haven't actually seen yet.
The Golden Rule of Git Rebase
Direct Answer
The practical rebase rule is: do not rewrite commits that other people depend on without coordinating with them. Rebase gives replayed commits new object IDs, so an unannounced force-push makes collaborators reconcile old and new histories. Rebase private work freely; use a documented coordinated rewrite only when the team accepts it.
Code Example
# Dev A pushes a feature branch (commits a1, e4, i7)
git push origin feature-payment
# Dev B pulls it and builds on top
git pull origin feature-payment
# Dev A rebases (rule broken) -> new commits m1, q4, u7
git switch feature-payment
git rebase main
git push --force origin feature-payment
# Dev B tries to pull the updated branch:
git pull origin feature-payment
# fatal: Need to specify how to reconcile divergent branches
# B's local i7 != remote u7 -> histories diverged, B's work is stranded
Common Mistakes & Pitfalls
- Rebasing after pushing: cleaning up a pushed branch with
-ithen force-pushing strands teammates' work. - Force-pushing
main/develop: breaks every clone at once and can cause production incidents. - Thinking new SHA = same commit: a changed SHA is a different commit to Git, which is the whole cause of divergence.
- Telling teammates to
reset --hard: that discards commits they built on the old history.
Check your understanding
Answer these without looking back at the article.
- What is the difference between git push --force and --force-with-lease?
- What exactly does a teammate see when they pull after you rebased a shared branch?
- Why does changing a commit's parent change its SHA?
Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.