Git Internals
Three-way merge mechanics
Understand how Git computes merges from base, ours, and theirs so conflicts and merge outcomes are easier to reason about.
- Readers building a durable Git mental model
- Developers who keep running into history, ref, or recovery confusion
- Comfort reading basic Git output
- A rough idea of commits, branches, and HEAD
- Learning low-level terms without connecting them to commands
- Collapsing objects, refs, and working state into one concept
Data & Performance
- merge basethe common ancestor is computed once; conflicts only arise where both sides changed the same regionSource: git-merge-base(1) official manual
Key Quotes
Git performs a three-way merge by finding the common ancestor (merge base) of the two commits and using it as the baseline to combine the two sets of changes.
Citations & Further Reading
- Git merge [Official]
- Git merge base [Official]
- Git Branching Basic Branching and Merging [Book]
What you will learn
- Understand the core purpose of Three-way merge mechanics
- Master the basic usage and common options of Three-way merge mechanics
- Understand how Git computes merges from base, ours, and theirs so conflicts and merge outcomes are easier to reason about.
- Understand key concepts: Inputs
- Know when to use this feature and when to avoid it
Git merge is a three-input computation: base, ours, and theirs.
Start with a problem
You use Git commands daily, but occasionally encounter 'strange' behavior — like being told a file changed when you didn't touch it, or unexpected conflicts during a rebase. You want to understand how Git works under the hood.
Inputs
base: common ancestor from merge-baseours: current branch tiptheirs: merged branch tip
Git compares base→ours and base→theirs, then synthesizes result.
Why conflicts appear
Conflicts occur when both sides changed overlapping regions and Git cannot choose semantics safely.
Practical takeaway
To resolve conflicts well, inspect base context instead of only choosing ours/theirs blindly.
A conflict means Git needs human intent where automatic reconciliation is ambiguous.
Good follow-up reads
Try it yourself
- Practice the three-way-merge-mechanics command in a test repository and observe state changes before and after
- Experiment with different options and compare the output differences
- Simulate a real scenario where you would need to use this, and walk through the full process
Further reading
Keep going on the same topic: