Chapter 5. Merging

[ 5 ]

Merging

In the last chapter, you learned about branches, and we discussed how they allow you to work on the same project in different ways and to collaborate with other people on a project.

In this chapter, you are going to learn about integrating changes from one branch into another. In Git, there are two ways to do this: merging and rebasing. We will cover rebasing in Chapter 11; for now we will focus on merging. This chapter will introduce the two types of merges (fast-forward merges and three-way merges), and you will carry out a fast-forward merge.

In the process, you will also learn about how Git protects you from losing any uncommitted changes, how changing branches may change the contents of the working directory, and how to check out commits directly.

State of the Local Repository

At the start of this chapter, you should have three commits and two branches in your rainbow repository, and you should be on the feature branch. The current state of the rainbow repository is illustrated in Visualize it 5-1.

[ Visualize it 5-1 ]

figure

The rainbow repository at the start of Chapter 5, with three commits and two branches

Introducing Merging

In Chapter 4, you created your first branch, feature, and started working on that branch. Branches are a powerful feature of Git, and it’s great that they allow us to work on different ...

Get Learning Git now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.