LinuxCommandLibrary

git-merge-tree

Preview merge without modifying tree

TLDR

Show merge result
$ git merge-tree [base] [branch1] [branch2]
copy
Check merge without merging
$ git merge-tree --write-tree [branch1] [branch2]
copy

SYNOPSIS

git merge-tree [options] base branch1 branch2

DESCRIPTION

git merge-tree performs a three-way merge without touching the index or working tree. It shows what a merge would produce, making it useful for previewing merges or performing scripted merge analysis.
The traditional mode requires specifying the base commit explicitly. Modern mode (`--write-tree`, added in Git 2.38) automatically finds the merge base and reports conflicts without actually merging, making it ideal for CI pipelines and automation scripts.

PARAMETERS

BASE

Common ancestor commit.
BRANCH1
First branch to merge.
BRANCH2
Second branch to merge.
--write-tree
Modern mode: write result tree.
--trivial-merge
Only trivial merges.
--help
Display help information.

CAVEATS

Plumbing command. Output format varies by mode. Modern mode added in Git 2.38.

HISTORY

git merge-tree is a Git plumbing command enhanced in Git 2.38 with --write-tree mode for easier programmatic merge testing.

SEE ALSO

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard