Progress:
TIER 2 · MODULE 22· Intermediate

git merge-tree

What would happen if I merged X into Y? Without touching either.

🎯 What & why

git merge-tree performs a trial three-way merge in memory and reports the resulting tree (and conflicts) without touching the index, working tree, or any branch. It answers 'would this merge cleanly?' for tooling and humans alike.

🧠 Mental model

A pure function: (base, ours, theirs) -> (tree, conflict list). No refs move, no files change; modern hosted platforms call this to compute mergeability badges.

🛠️ Synopsis

git merge-tree [--write-tree] [--merge-base=<commit>]
               [--no-messages] [--name-only] [-z]
               <branch1> <branch2>

🎚️ Switches & options

FlagWhat it does
--write-treeModern mode: actually compute and write the merged tree, return its OID.
--merge-base=<commit>Override the auto-detected merge base.
--no-messagesSuppress informational conflict messages; just emit the data.
--name-onlyOutput only conflicting paths, not full conflict info.
-zNUL-terminate path output for safe scripting.

💡 Use cases

🧪 Examples

Trial merge, write the resulting tree
git merge-tree --write-tree feature main
Just the conflicting paths, NUL-separated
git merge-tree --write-tree --name-only -z feature main
Force a specific merge base
git merge-tree --write-tree --merge-base=abc123 feature main
Quiet mode for tooling
git merge-tree --write-tree --no-messages feature main

🎓 Recommendations

🪤 Common pitfalls

🔗 Related modules

📝 Quiz

Hit each option, then Check answers. Score is recorded; Next is always open.