git rebase
Reapplies commits on top of another base tip, creating a linear history.
Syntax
git rebase [<options>] [<upstream> [<branch>]]
Options
- -i / --interactive: Opens an editor to reorder, squash, edit, or drop commits
- --onto <newbase>: Rebases onto a specific base instead of the upstream
- --abort: Aborts the rebase and returns to the original branch state
- --continue: Continues after resolving conflicts
- --skip: Skips the current patch and continues
- --autosquash: Automatically applies fixup! and squash! commits
Example
git rebase main git rebase -i HEAD~3 git rebase --onto main feature/old feature/new
Tip
Never rebase commits that have been pushed to a shared repository.