git merge-tree
Patching & Rewriting
Compute a merge without touching the working tree
The 'git merge-tree --write-tree' command performs a merge entirely in memory: it prints the id of the merged tree and, if there are conflicts, the conflicted files and messages — without changing your files, the staging area or any branch. It exits with 1 on conflicts, which makes it ideal for scripts and servers that need to know whether two branches would merge cleanly.
Synopsis
git merge-tree --write-tree [--name-only] <branch1> <branch2>[ ] optional| or<arg> placeholder... repeatable--flag option
Examples
Test a merge
git merge-tree --write-tree main featureClean: prints a tree id; conflicts: exit code 1.
Just the conflicted files
git merge-tree --write-tree --name-only main featureFile names instead of stages.
Workflow Examples
1
git merge-tree --write-tree main feature || echo "conflicts"Exit code 1 means conflicts
Troubleshooting
usage: git merge-tree … (old mode output)
Cause: Old Git versions only have the trivial mode
Update Git (--write-tree needs 2.38+)
Tips & Pitfalls
Best Practices
- ✓Use the exit code in scripts: 0 clean, 1 conflicts.
Common Mistakes
- ✗Expecting a merge commit — merge-tree only computes the result.
FAQ
A:
The tree the merge would produce; you could commit it with git commit-tree.