Skip to content
IT glossary
ProgrammingUpdated December 3, 2026

Rebase

A Git operation that replays the changes from your branch’s commits on top of a new starting point. It’s often used to update a feature branch with the latest work from the main branch.

Also known as: ребейз

What rebase does

Suppose you start a feature branch on Monday. By Friday, two things have happened: you’ve committed your changes, and your teammates have added commits to main. Rebasing your feature branch onto main makes your work appear after those newer commits, as if you’d started the feature on Friday.

What happens to the commits

In a typical rebase, Git identifies the commits to replay, then applies their changes one at a time, starting at the tip of the target branch. When it finishes, Git points your branch at the last replayed commit. The target branch stays where it was.

Before:                  After:
A---B  main              A---B  main
 \                            \
  C---D  feature               C'---D'  feature

C' is not just C in a new spot. A commit ID depends in part on the commit’s parent, so putting the same change on a different parent produces a new commit ID. That’s what people mean when they say rebase rewrites history: the branch points to a new chain of commits rather than changing the old commits in place.

Example: update a feature branch

Start with a clean working tree. Fetch first so you rebase onto the latest main you’ve retrieved from origin, rather than a potentially stale local main:

git fetch origin
git switch feature
git rebase origin/main

If a commit can’t be applied cleanly, Git pauses. Resolve the conflicts, stage the resolved files with git add <file>, then run git rebase --continue. Because Git is replaying individual commits, it can pause again on a later one. To abandon an in-progress rebase and return to where you started, run git rebase --abort.

When to use it

Rebase is useful on a feature branch you own: it lets you test your changes against the latest base and keeps the history easy to read. Interactive rebase is also useful before review. For example, git rebase -i HEAD~3 lets you reorder, combine, or reword the last three commits in a simple linear history.

Avoid rebasing commits that teammates have built on unless you’ve coordinated the rewrite. Their branches still contain the original commits. If your team allows you to update a published feature branch after a rebase, prefer git push --force-with-lease to --force: the lease checks the remote tip against an expected value, but it doesn’t tell you whether someone is relying on the old history.

What interviewers look for

Be ready to draw the result of merging versus rebasing two branches that have diverged. A regular merge keeps the existing commits and connects the histories with a merge commit. A rebase recreates the feature commits on top of the target branch. Don’t say that merge always adds a commit: when the branch being merged into is already an ancestor of the other branch, Git can fast-forward it instead.