Information Technology Reference
In-Depth Information
Solution
Clone the repository from Recipe 6-1 with branches:
$ cd git-recipes
$ git clone-with-branches 06-01 06-02
$ cd 06-02
Right now you are on the
master
branch. Merge the
feature
branch into the
master
branch with the
$ git merge feature
command. The command will
print the information that this operation was carried on as a fast-forward. When you
finish, the
master
branch contains all the files created in
master
branch as well as
three files from
feature
branch. The
$ ls
command will print six filenames:
f1.txt
,
f2.txt
,
f3.txt
,
m1.txt
,
m2.txt
, and
m3.txt
.
How It Works
This recipe presents the simplest example of merging branches. There are two branches
master
and
feature
, and the current branch is
master
. A very important fact is
that all the revisions in the
master
branch are contained in the
feature
branch. We
say that the
master
branch is merged into the
feature
branch. This relation was
defined in Recipe 5-9.
in the
master
branch just moves the
master
pointer to the place referenced by the
feature
branch. This operation is called
fast-forward
. It is the least complicated ex-
ample of joining two development histories. The resulting repository contains two
branches pointing to exactly the same commit. Notice that during fast-forward no new
commits are created.
Keep in mind that the history will contain no information at all that we used the $
git merge command. The name of the feature branch can disappear from the history.
This can be regarded as a drawback. We will circumvent this drawback in Recipe 6-6.
You also can try to merge the
master
branch into the
feature
branch. What
would happen in that case? Because the
master
branch is already merged into
fea-
ture
branch the commands: