Git Cheat Sheet · Integrate

Rebase a branch

git rebase <branch>

git rebase <branch> replays your commits one by one on top of another branch, as if you had started your work from its last commit. History stays linear, but your commits are recreated with new identifiers.

What it does

Replays the commits of the current branch on top of another, for a linear history.

A use case

main moved forward during your work: you update your branch before proposing it.

Warning: Rewrites the commits of your branch: if it is already published, a force push will be needed.

On the command line

git fetch && git rebase origin/main
Brings your branch up to date with main.
git rebase --continue
Resumes after you have resolved a conflict and staged the files.
git rebase --skip
Drops the commit being replayed.
git rebase --abort
Cancels the whole rebase.
git push --force-with-lease
Republishes the rebased branch.

In Merathon

  1. Switch to your working branch.
  2. Right-click the target branch → "Rebase <current branch> onto <branch>".
  3. In case of conflict, resolve it then click "Continue" in the right panel's banner.

Frequently asked questions

Should I merge or rebase?

Rebase to update your own branch before a pull request. Merge to integrate a finished branch, or as soon as others work on the same branch.

Why is my push refused after a rebase?

The commits were recreated: the remote branch is no longer an ancestor of yours. You need a force push, preferably with --force-with-lease.

See also