Chapter 10. Merging branches

 

In the preceding chapter, you created multiple branches, diverging your code base. You learned that when you work on a branch, you’re working on a separate line of development. If you want to incorporate the work from your separate branch back into your main line of development, you need to use git merge, as shown in figure 10.1.

Figure 10.1. A typical merge. The commits are the boxes with letters.

Branching diverges code bases, and merging converges code bases. In figure 10.1, we diverge the code base at commit B, making two branches: master and new_feature. We then make some commits on both branches. Next, using git merge, we converge new_feature and master back together in commit F. git merge is the focus of this chapter, as well as some of the graphical tools accessed by git mergetool (you’ll see a few of them). Because producing branches is so easy, the git merge command is an important tool.

10.1. Considering point of view: Traffic merges into us

When you run the git merge command, you merge branches into whatever branch you have currently checked out, as shown in figure 10.2.

Figure 10.2. Branches merge into whatever branch you’re on.

10.2. Performing a merge

10.3. Handling merge conflicts

10.4. Performing fast-forward merges

10.5. Lab

10.6. Further exploration

10.7. Commands in this chapter

sitemap