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:
- Checkout the latest Commit on the master branch
- Replay one commit at a time from
new
ontomaster
- Update the
new
branch to point to the last replayed commit. - The rebase doesnt afect
master
whilenew
has all the changes frommaster
.