What is a Merge
A merge combines two (or more) branches into a single branch by creating a new commit with multiple parents. The merge commit represents the point where divergent histories were integrated.
How it works
Git's three-way merge uses three inputs: the merge base (the most recent common ancestor of both branches), ours (current branch tip), and theirs (branch being merged).
For each file, Git compares the merge base version to both tips:
- Only one side changed → take that side.
- Neither side changed → keep the merge base version.
- Both sides changed different regions → combine both changes.
- Both sides changed the same lines → conflict — manual resolution required.
If the target branch has not diverged (the branch being merged is strictly ahead), Git performs a fast-forward instead — no merge commit needed.
A merge commit has two parent pointers, preserving the complete branch topology in the DAG. You can see exactly when a branch was created and when it was integrated.
Why it matters
Merging is the primary mechanism for integrating parallel work. The three-way merge algorithm handles most cases automatically. Understanding the merge base concept explains why long-lived branches produce more conflicts — the merge base diverges further from both tips.
See How Git Merging Works for fast-forward, three-way merge, squash, and octopus merge strategies.