Interview Q&A / Git & GitHub

IntermediateQuick answer1 min readUpdated 3 Oct 2026

How does a three-way merge work in Git?

SHORT ANSWER

Git compares three snapshots: the two branch tips and their common ancestor. Changes made on only one side are taken automatically; if both sides changed the same lines differently, Git reports a conflict.

Explain it simply

Two students edit copies of the same assignment. To combine them fairly you need the original too. If only Asha changed a paragraph, keep her version. If only Ravi changed it, keep his. If both rewrote the same sentence differently, a human must decide.

Git does exactly this with the merge base, the latest commit both branches share. Comparing each tip with the base tells it who changed what. Non-overlapping changes merge cleanly into a new commit with two parents. Overlapping ones produce conflict markers. A two-way comparison without the base could not tell 'one side changed it' from 'both sides disagree'.

Example

bash
git merge-base main feature     # prints the common ancestor hash
git merge feature               # creates a merge commit with two parents
git log --oneline --graph

What to say in the interview

"Git finds the merge base, the closest common ancestor, and diffs both branch tips against it. Changes on one side are applied automatically, and changes to the same region on both sides cause a conflict. The result is a merge commit with two parents."

#git#merge#algorithm

Related questions

Practise more Git & GitHub questions

Test your recall with short answers, then return to the detailed explanations when you need context.

Open Git & GitHub quick answers →

Get new questions like this by email

One short email when something new and useful lands. No spam, unsubscribe in one tap.

By subscribing you agree to the Privacy Policy.