In-Memory Merging and Merge Queues — Quick Reference
Core Command Syntax
git merge-tree --write-tree <branch1> <branch2>
| Flag |
Description |
--write-tree |
Executes 3-way merge in memory and returns root tree SHA |
--merge-base=<commit> |
Overrides the common merge ancestor commit |
--name-only |
Lists only the names of conflicting files |
--no-messages |
Suppresses informational merge messages |
--messages |
Includes informational messages (default) |
--allow-unrelated-histories |
Allows merging branches that share no common ancestor |
--trivial-merge |
Disallows 3-way file content merges |
Common Patterns
1. Mergeability check in CI
if git merge-tree --write-tree --name-only origin/main HEAD >/dev/null 2>&1; then
echo "Clean merge"
else
echo "Conflicts detected"
fi
2. Synthesize a merge commit
TREE=$(git merge-tree --write-tree --no-messages origin/main feature/branch)
P1=$(git rev-parse origin/main)
P2=$(git rev-parse feature/branch)
COMMIT=$(git commit-tree "$TREE" -p "$P1" -p "$P2" -m "Merge feature/branch into main")
echo "Synthetic commit SHA: $COMMIT"
# Output list of conflicted files
git merge-tree --write-tree --name-only origin/main feature/branch | tail -n +2
4. Rebase simulation
BASE=$(git merge-base origin/main feature/branch)
if git merge-tree --write-tree --merge-base="$BASE" origin/main feature/branch >/dev/null 2>&1; then
echo "Clean rebase possible"
else
echo "Rebase conflict detected"
fi
Exit Code Matrix
| Exit code |
Meaning |
Action |
0 |
Clean merge |
Safe to create commit or advance queue |
1 |
Merge conflicts |
Reject pull request or eject from queue |
>1 |
Fatal error |
Check branch names and repository state |