Lesson
Merging
Fast-forward vs three-way merges, merge commits, and where conflicts come from.
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
Empty folder
Run git init to create a repository.
Working directory
Clean — no uncommitted changes.
Staging area
Nothing staged. Run git add.
Repository
No commits yet.
A fast-forward merge simply advances main to the feature tip.
Commands used
git switch -c feature
git add feature.ts
git commit -m "feat"
git switch main
git merge featureCommon 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 itSummary
- Fast-forward moves a pointer.
- Three-way merge creates a two-parent commit.
- Conflicts come from overlapping edits.