Skip to content
rajin

17Fast-forward and three-way merging

intermediate25–30 minHandbook pp. 39–40 Not started

Warm-up · from “Stash, shelving and worktrees”

What is the second parent of a normal stash commit?

No notes: write what you remember, then check. Recalling before reading is what makes it stick.

The problem

Two developers complete separate features. How does Git combine them without losing either person's changes?

After this lesson you can

  • Identify fast-forward and divergent histories.

  • Locate a merge base.

  • Explain the resulting parent links.

Key terms

Full glossary

Say what each term means, then open it to check.

  • Merge base · new in this lesson

    Best common ancestor of commits; there may be several.

  • Index · from lesson 9

    Prepared path-to-object entries, plus metadata and conflict stages.

  • Commit · from lesson 7

    Object identifying a root tree, parent(s), metadata and message.

  • Tree · from lesson 6

    Directory snapshot mapping names, modes and object IDs.

Visual mental model

  1. Base A
  2. Ours: Bmain
  3. Theirs: Cfeature
  4. Merge Mtwo parents
Arrows show parent links (from child to parent). Branch labels identify tips.

Build the mental model

If the current tip is an ancestor of the incoming tip, a normal merge can fast-forward: move the current branch to the incoming commit and update the Index and working tree. No new commit is needed. If the incoming tip is already an ancestor, there is nothing to integrate. --no-ff can request a merge commit even when fast-forward is possible; --ff-only refuses divergence.

SimulationFast-forward vs three-way merge

A simplified model for building intuition. It does not read your sandbox; use the terminal for real behaviour.

Under the hood

For diverged histories, Git finds a best common ancestor (there may be multiple) and compares the base, ours and theirs. Changes on only one side generally carry forward; independent edits may combine automatically. Conflicting edits require a resolution. The default ort strategy handles details such as renames and multiple merge bases. A successful ordinary divergent merge produces a commit with both tips as parents.

Common mistake · important nuance

A merge is not a blind overlay of one folder onto another. The base helps distinguish additions from deletions.

Move between parts freely. Completion counts only what you verify and answer.