Lesson 3 of 7 · 9 min
Branching, merging and resolving conflicts
Why branching is cheap, what a merge commit really is, and how to resolve conflicts without guessing.
Fast-forward versus merge commit
If the target branch has no commits that yours lacks, Git can just slide the pointer forward — a fast-forward. No merge commit, no new content, and the history stays linear.
If both branches have moved, Git finds the common ancestor, computes what each side changed since then, and combines them into a new commit with two parents. That two-parent commit is what records that a merge happened.
Controlling the shape
| Flag | Effect | Use when |
|---|---|---|
| --ff (default) | Fast-forward when possible | Small changes where the branch is not meaningful |
| --no-ff | Always create a merge commit | You want the feature branch visible in history |
| --ff-only | Fail rather than create a merge commit | Enforcing a linear history |
| --squash | Combine all changes into one staged change | Collapsing a messy branch into one commit |
<<<<<<< HEAD
const timeout = 30; # what your current branch has
=======
const timeout = 60; # what the branch you are merging has
>>>>>>> feature/slow-api
# Resolve by editing to the correct final content — often neither side
# verbatim — then remove all three markers and stage it:
git add config.js
git merge --continue # or: git commitNote: Leaving a marker in the file is the classic mistake. Grep for '<<<<<<<' before committing.
Getting more context
merge.conflictStyle set to zdiff3 adds a third section showing the common ancestor. Seeing what the code was before either side touched it usually makes the correct resolution obvious, and it is the single most useful Git setting most people have never enabled.
git merge --abort returns you to the pre-merge state at any point. There is no reason to fight through a merge you have lost track of.
Worth remembering
- A branch is 41 bytes — cheapness is why Git workflows look the way they do.
- A fast-forward moves the pointer; a real merge creates a commit with two parents.
- Conflicts arise only when both sides changed the same region.
Test it now
Merge behaviour and conflict resolution dominate the medium bank.