Chapter 6. Merges

Because Git is a distributed version control system, it allows developers in dispersed geographical locations to make and record changes independently, and it permits two or more developers to combine their changes at any time, all without a central repository. Technically, this is an operation that combines two or more different lines of development, and it is formally known as a merge in Git.

In this chapter, we’ll explain how to merge two or more different lines of development via some simple merge examples, and we’ll share some techniques for resolving a merge conflict when it occurs. We will also discuss merge strategies in Git and take a peek at what happens in the Git object store when a merge operation is executed.

Merge: A Technical View

In Git, a merge unifies two or more commit histories of branches. Most often, a merge unites just two branches, although Git supports a merge of three or more branches at the same time.

A merge must occur within a single repository—that is, all the branches to be merged must be present in the same repository. How the branches come to be in the repository is not important. (As you will see in Chapter 11, Git provides mechanisms for referring to other repositories and for bringing remote branches into your current working repository.)

When modifications in one branch do not conflict with modifications found in another branch, Git computes a merge result and creates a new commit that represents the new, unified ...

Get Version Control with Git, 3rd Edition 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.