git rebase Replay your commits on top of another base

Moves a branch so it starts from a newer commit, creating a straight, tidy history. The interactive mode also lets you reorder, squash, reword or drop commits.

Synopsis

git rebase [OPTION]... [UPSTREAM]
git rebase -i BASE

Common options

Option or formWhat it does
-i, --interactiveEdit the list of commits to pick, squash, reword or drop
--continueCarry on after you fixed a conflict
--abortStop and return to how things were before
--onto NEW OLDTransplant commits that follow OLD onto NEW
--autosquashFold fixup! commits into the commits they fix

Examples

Update your branch onto latest main
git fetch origin
git rebase origin/main
Tidy the last 3 commits
git rebase -i HEAD~3
After resolving a conflict
git add app.js
git rebase --continue
Escape a rebase gone wrong
git rebase --abort

Notes

See also

Last reviewed 2026-10-09.