Skip to content

Lesson

Merging

Fast-forward vs three-way merges, merge commits, and where conflicts come from.

Intermediate 8 min read

Learning objectives

  • Distinguish fast-forward from three-way merges
  • Understand the role of the merge base
  • Know when conflicts occur

Fast-forward

If your branch is directly behind the branch you are merging, Git just moves your pointer forward. There is no divergent work, so no merge commit is needed.

Three-way merge

When both branches have new commits, Git finds their common ancestor (the merge base) and combines the two sets of changes into a new merge commit with two parents.

Conflicts

If both branches changed the same lines relative to the merge base, Git cannot choose automatically. It marks the file and pauses so you can resolve it.

Try it yourself

interactive visualization

Empty folder

Run git init to create a repository.

Working directory

Clean — no uncommitted changes.

git add ↓

Staging area

Nothing staged. Run git add.

git commit ↓

Repository

No commits yet.

1/6Empty repositoryOpen in visualizer

A fast-forward merge simply advances main to the feature tip.

Commands used

terminal
git switch -c feature
git add feature.ts
git commit -m "feat"
git switch main
git merge feature

Common mistakes

  • Merging into the wrong branch.
  • Committing conflict markers.

Best practices

  • Sync with the target branch before merging.
  • Read the diff after resolving conflicts.

Mini challenge

Create a scenario where a merge produces a merge commit with two parents.

Open the visualizer to try it

Summary

  • Fast-forward moves a pointer.
  • Three-way merge creates a two-parent commit.
  • Conflicts come from overlapping edits.
Next lessonRebase