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 form | What it does |
|---|---|
-i, --interactive | Edit the list of commits to pick, squash, reword or drop |
--continue | Carry on after you fixed a conflict |
--abort | Stop and return to how things were before |
--onto NEW OLD | Transplant commits that follow OLD onto NEW |
--autosquash | Fold fixup! commits into the commits they fix |
Examples
git fetch origin
git rebase origin/main
git rebase -i HEAD~3
git add app.js
git rebase --continue
git rebase --abort
Notes
- Rebase rewrites commits, giving them new hashes. Do not rebase commits other people already have.
- After rebasing a branch you pushed earlier, push with git push --force-with-lease, which fails if someone else pushed in the meantime.
- If you get lost, git reflog shows where you were before the rebase.
See also
Last reviewed 2026-10-09.