Merging Step by Step
Learn how to merge two branches in your git repository.
Step 1: Creating a repository, adding some files, and committing them#
Take a look at the following slides and see how merging takes place:
Merging feature1 branch to master
1 of 2
You can run through the same kind of scenario step-by-step by following these commands:
1 mkdir -p lgthw_merging
2 cd lgthw_merging
3 git init
4 echo A > file1
5 git add file1
6 git commit -am 'A'
7 echo B >> file1
8 git commit -am 'B'
9 echo C >> file1
10 git commit -am 'C'
Now, you are at this point of the process:
Step 2: Creating a branch and checking it out#
Branch to experimental
and make your changes:
11 git branch experimental
12 git checkout experimental
13 git branch
14 echo E >> file1
15 git commit -am 'E'
16 echo H >> file1
17 git commit -am 'H'
The repository is in this state:
Step 3: Checking out master, and making more changes#
Return to master
, and make changes D
, F
and G
:
17 git checkout master
18 git branch
19 echo D >> file1
20 git commit -am 'D'
21 echo F >> file1
22 git commit -am 'F'
23 echo G >> file1
24 git commit -am 'G'
The repository is in this state:
Step 4: Attempting to merge the master
and experiment
branch#
And you are ready to merge:
25 git merge experimental
Oh dear, that does not look good. The merge failed with a CONFLICT
message.
A Toy Merging Example
Handling Merge Conflicts
Mark as Completed
Report an Issue