Definition
What it is
When you merge branch A into branch B, Git finds the common ancestor C. If B is a direct descendant of A's tip, Git "fast-forwards" B to A's tip: no merge commit is needed, the history is linear. If A and B diverged (both have commits C does not have), Git performs a three-way merge: it combines the diffs A-C and B-C, creates a new commit M with two parents (A and B), and B's pointer moves to M.
A merge never rewrites history. Both A's and B's commits survive intact. That is the defining property of a merge and the reason it is safe: it does not touch what already happened.
Why it matters
A merge is the tool for combining divergent work without destroying either side. The trade-off is history shape: a merge creates a "bubble" in the graph (two parents join into one commit), which some teams find noisy. Rebase is the alternative when a linear history is preferred, at the cost of rewriting commits.
Merge vs rebase vs squash vs cherry-pick
Aspect | Merge | Rebase | Squash | Cherry-pick |
|---|---|---|---|---|
History shape | Bubble | Linear | Linear, one commit | Duplicated commit |
Rewrites history | No | Yes | Yes | No (new commit) |
Preserves branches | Yes | No | No | N/A |
Conflict resolution | Once at merge time | Per commit replayed | Once | Once per commit |
Typical use | Feature → main | Feature onto latest main | Cleanup before merge | Port a fix |
The three-way merge
graph TD C[Common ancestor C] --> A[Branch A tip] C --> B[Branch B tip] A --> M[Merge commit M] B --> M style C fill:#FFF3E0 style M fill:#E8F5E9
How to merge without breaking
Merging without pain
Merge small branches
A 20-commit branch conflicts more than a 2-commit branch. Merge daily, not monthly.
Resolve conflicts locally
Read every conflict mark; do not blindly accept "theirs". A wrong conflict resolution is a silent bug.
Use `--no-ff` for feature branches
A merge commit records the merge in history.
git merge --no-ff feature/xmakes it visible.Write the merge message
Default is "Merge branch 'x' into 'y'". If the branch has 20 commits, list them in the body. Future-you will thank you.
Common failures
Origin
The word comes from Latin mergere, "to dive, to plunge, to immerse". English used it in the 17th century for combining streams and rivers. Version control adopted it in the 1980s for combining two divergent histories of the same file. Git in 2005 formalized the three-way merge as the default: find the ancestor, combine the diffs, create the merge commit with two parents.
Merging is the operation of bringing two or more branches together. The result is a new commit with multiple parents, or a fast-forward move if one branch is a direct descendant of the other.
— Chacon & Straub, *Pro Git*, 2014 (paraphrase)
Evidence
FAQ
- How are conflicts computed?
Three-way: compare A, B and C. Conflicts appear only where A and B both changed the same line relative to C.
- When to use `--no-ff`?
For feature branches, always. It preserves the merge in history as a distinct event.
- What is a fast-forward?
When B has not moved since A branched, merging A into B just moves B's pointer. No merge commit.
- Merge vs rebase?
Merge preserves both histories, safe but noisy. Rebase rewrites one side onto the other, clean but destructive.
Connections
Chacon, S. & Straub, B. (2014). Pro Git, Chapter 3. https://git-scm.com/book/en/v2/Git-Branching-Basic-Branching-and-Merging
Git project (2024). git-merge(1). https://git-scm.com/docs/git-merge
Atlassian (2024). Merging vs rebasing. https://www.atlassian.com/git/tutorials/merging-vs-rebasing
Etymology
Origin: borrowed
merge(verb): from Latin mergere, "to dive, to plunge"
Semantic network
● broader ● narrower ● related
Used in the garden
- The Integrated Strategy Guide: Branding, SEO, and Digital Marketing in Harmony (1×)
- Automate to Liberation: The 5‑Tool Stack That Runs Your Business (1×)
- Family Business Succession in Argentina: The Digital Dilemma (1×)
- The Hybrid Content Strategy: Where Brand Storytelling Meets SEO Precision (1×)
- The Ultimate Digital Marketing Guide: Strategies for Sustainable Growth (1×)
- Unlock Google's Visual Secrets: A Practical Guide to Rich Snippets for Niche E-commerce (1×)
- The Best-Kept Secret: Investment Opportunities Few Know About (1×)
- Marketing Automation, Growth Hacking, and Affiliate Marketing: The Complete Guide (1×)
- 10 Secret Websites That Will Unlock Your Day (And Your Potential!) (1×)
- The Secret Arsenal for Creators! 10 FREE Web Apps That Will Skyrocket Your Digital Success (Creators & Entrepreneurs Edition) (1×)
- Marketing Automation: Building Flows That Convert on Autopilot (1×)
Sources
Chacon, S. & Straub, B. (2014). Pro Git. https://git-scm.com/book/en/v2/Git-Branching-Basic-Branching-and-Merging
Git project (2024). git-merge(1). https://git-scm.com/docs/git-merge
Atlassian (2024). Merging vs rebasing. https://www.atlassian.com/git/tutorials/merging-vs-rebasing