git-rebase

Reapply commits on new base

TLDR

Rebase onto branch
$ git rebase [branch]
Interactive rebase
$ git rebase -i [commit]
Rebase last N commits
$ git rebase -i HEAD~[n]
Continue after conflict
$ git rebase --continue
Abort rebase
$ git rebase --abort
Skip current commit
$ git rebase --skip
Rebase onto specific base
$ git rebase --onto [newbase] [oldbase] [branch]

SYNOPSIS

git rebase [options] [upstream] [branch]

DESCRIPTION

git rebase reapplies commits on top of another base tip, producing a linear project history. It finds the common ancestor of the current branch and the upstream, then replays each commit from the current branch onto the upstream tip.Interactive mode (`-i`) allows reordering, squashing, editing, or dropping commits during the replay, making it a powerful tool for cleaning up commit history. The `--onto` option enables advanced workflows like moving a branch to an entirely new base. Autosquash automatically applies fixup! and squash! commits, supporting the iterative fixup workflow.

PARAMETERS

-i, --interactive

Interactive mode.
--onto newbase
Rebase onto different base.
--continue
Continue after resolving.
--abort
Cancel rebase.
--skip
Skip current patch.
--autosquash
Auto-apply fixup/squash.
--autostash
Auto-stash changes.
-x cmd
Run command after each commit.
-r, --rebase-merges
Recreate merge commits instead of flattening history (replaces the deprecated `--preserve-merges`).

INSTALL

sudo apt install git
sudo dnf install git
sudo pacman -S git
sudo apk add git
sudo zypper install git
brew install git
nix profile install nixpkgs#git

CAVEATS

Rebasing rewrites history. Don't rebase commits that have been pushed to shared branches.

SEE ALSO

git-merge(1), git-cherry-pick(1), git-reset(1)

RESOURCES

Source code · Homepage · Documentation