git rebase <branchname>
reapply commits from the current branch onto <branchname>
This command moves the entire commit history of the current branch to start from the latest commit of <branchname>
. It effectively replays the commits of your current branch on top of the commits from <branchname>
.
This doesn't produce a new merge commit but instead rewrites the commit history.
Variations include using -i
for an interactive rebase, allowing you to edit, reorder, or squash commits. Another variant is --continue
to proceed after resolving conflicts, or --abort
to cancel the rebase. To rebase on the tip of your commits, you can use --onto <newbase>
.
Specific examples:
git rebase main