git rebase — rewriting history

See git rebase replay your branch's commits onto a new base. Understand why hashes change (c3') and the golden rule of rebasing.

Scenario

Speed
c1initc2base featurec3feat Ac4feat Bc5hotfixc3'feat Ac4'feat BmainHEADfeature

Branch state

mainc5
featurec4'◀ HEAD

Current step 10/10

$ git rebase main

feature's commits are replayed on top of main. c3 and c4 are abandoned and identical c3', c4' appear — that's why hashes change. You get linear history, but never rebase a branch others have pulled.

$ git log --oneline --all

c4' (HEAD -> feature) feat B

c3' feat A

c5 (main) hotfix

c2 base feature

c1 init

File content (at HEAD) — app.js @ feature

1initc1
2basec2
3hotfixc5
4featAc3'
5featBc4'
−featAc3 removed
−featBc4 removed
commit abandoned commitHEAD HEAD

Circles are commits; dimmed circles were abandoned by rebase/reset. A prime (c3') means same content, rewritten hash. In sandbox mode, run commands yourself with the buttons.

git rebase replays your branch's commits on top of another branch's tip. Your feature commits are restacked onto the newest main, producing a straight line — as if you'd started from the latest main all along.

The commits are copied, not moved. The originals are abandoned and new commits with the same content but different parents appear — shown as c3' in the simulator. Since a commit's hash is computed from content plus parent, every rebased commit gets a new hash.

That's the golden rule: never rebase a shared branch. If teammates have your old commits and you rewrite them, their history and yours diverge and everything tangles. Rebase is safe only for local branches you haven't pushed. Git Branch Simulator

Frequently asked questions

Why do commit hashes change after rebase?
A hash is computed from content plus the parent hash. Rebase changes the parent, so identical content still produces a different hash — the old commits are replaced by prime (c3') copies.
How does rebase differ from merge?
Merge keeps the branch structure with a two-parent merge commit; rebase replays commits to create linear history. The resulting files can be identical, but the history shape differs completely.
Why shouldn't I rebase a pushed branch?
Others built work on your old commits. Rewriting them to new hashes means the histories no longer share ancestry, so the next pull produces duplicated commits and conflicts.

Other scenarios

Related tools