Skip to main content

GitKit (Linux Desktop Edition): Learn git and GitHub in Context

Section 5.3 Merging the main Branch into a Feature Branch

Your local main branch now contains the changes that were made to the upstream main branch. The next step is to merge the changes from the main branch into your feature branch. This is like the example from class, which is illustrated in Figure 5.3.1.
Figure 5.3.1 shows the main branch in the right panel, the contributor’s feature branch in the left panel, and the common ancestor in the middle.
main branch timeline with feature branch merge
Figure 5.3.1. Merge main into feature branch

Exercises

1.

2.

The git merge <branch name> command will attempt to merge the changes in the active branch with the changes in <branch name> (i.e. the source branches) into a merge commit in the currently active branch (i.e. the target branch).
(a)
To use the merge command as just described your feature branch (i.e. the target branch) must be the active branch. Switch to your feature branch and confirm that it is now the active branch.
What were the commands you used? And their output? You can copy your work into the provided textbox.
(b)
Use the merge command to try to merge the changes contained in the main branch and in your feature branch into your feature branch.
What were the commands you used? And their output? You can copy your work into the provided textbox.

3.

The output from Exercise 5.3.2 should indicate that the automatic merge failed due to a conflict. If your merge command did not fail due to a conflict, return to Exercise 5.2.4 and follow the instructions from there again.
(a)
In which file is the conflict located?
(b)
Use the cat command to display the file containing the conflict.
Find the part of the file that contains the raw conflict information and copy and paste it here. Be sure to include the chevrons at the top and bottom of the conflict information.

4.

Answer the following questions by copying the appropriate portion of the output that you gave in Task 5.3.3.b.
(a)
What is the part of the output that is the Best Common Ancestor?
(b)
What is the part of the output that shows the changes that the maintainers merged into the main branch after you made your feature branch?
(c)
What is the part of the output that shows your changes?

5.

Sometimes when you try to merge, and it fails due to a conflict you may want to undo the attempted merge. The git merge --abort command will undo a failed merge.
Undo the merge that you started in Exercise 5.3.2 and use the cat command to display the file that contains the conflict again.
Briefly explain how you can tell from the output of cat that the failed merge has been undone?
You have attempted of activities on this page.