Information Technology Reference
In-Depth Information
CHAPTER 7
Rebasing Branches
You can join two different development histories with the
$ git merge
and
$ git
rebase
commands. In this chapter we will deal with rebasing. Merging was discussed
in the previous chapter.
Generally speaking rebasing is a method for converting divergent branches into linear
history. You can think about it as an automatic cherry-picking operation for moving a
series of commits from one place on the graph to another. The advantages of using re-
basing will become apparent when you start to cooperate with other developers in the
same repository. By using the rebasing command you will be able to produce a clean lin-
ear history of your project.
We will start with an in-depth explanation of rebasing divergent branches. We will
perform this operation using three different approaches:
• With the
$ git rebase
command
• With the
$ git format-patch
and
$ git am
commands
• With the
$ git cherry-pick
command
This will provide you with a solid background and deep understanding of the way re-
basing works.
Then we will proceed with joining disjointed branches using
$ git rebase
solely
(i.e., without the
$ git merge
command). There you will learn to fast-forward di-
verged branches with rebasing.
Next we will cover the problem of moving only a part of your new branch. This can
be done thanks to the
--onto
parameter of the
$ git rebase
command, and it ap-
plies to scenarios where your repository contains three or more divergent branches. This