Skip to content

In-Memory Merging and Merge Queues — Quick Reference ​

Core Command Syntax ​

bash
git merge-tree --write-tree <branch1> <branch2>
FlagDescription
--write-treeExecutes 3-way merge in memory and returns root tree SHA
--merge-base=<commit>Overrides the common merge ancestor commit
--name-onlyLists only the names of conflicting files
--no-messagesSuppresses informational merge messages
--messagesIncludes informational messages (default)
--allow-unrelated-historiesAllows merging branches that share no common ancestor
--trivial-mergeDisallows 3-way file content merges

Common Patterns ​

1. Mergeability check in CI ​

bash
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 ​

bash
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"

3. Extract conflicting file paths ​

bash
# Output list of conflicted files
git merge-tree --write-tree --name-only origin/main feature/branch | tail -n +2

4. Rebase simulation ​

bash
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 codeMeaningAction
0Clean mergeSafe to create commit or advance queue
1Merge conflictsReject pull request or eject from queue
>1Fatal errorCheck branch names and repository state

Git Master — Git Reference for Every Skill Level