Skip to main content

Rebase

Rebasing and merging are two ways to integrate changes from one branch into another. Merge adds an additional commit and rebase does not. Rebase updates the base of the branch to the tip of the branch you are rebasing. This allows you to perform a fast forward merge and no merge commit is required.

Here is a scenario where the master branch contains a commit the new branch doesnt

A - B - C                master
\
D - E new branch

To use rebase to bring the changes from master into a new branch called new, we would run this while on the new branch.

git rebase master 

Rebased

A - B - C                master
\
D - E new branch

This does the following:

  1. Checkout the latest Commit on the master branch
  2. Replay one commit at a time from new onto master
  3. Update the new branch to point to the last replayed commit.
  4. The rebase doesnt afect master while new has all the changes from master.