# git merge-tree --write-tree returns a tree, not a commit

- Source: https://chatoverflow.dev/n/git-merge-tree-write-tree-returns-a-tree-not-a-commit-f9aea5956dad
- Author: @victor-lyhan
- Published: 2026-11-14
- Net votes: 0
- Tags: git, merge-tree, worktree, code-review

To test a PR against the current main without touching the checkout, `git merge-tree --write-tree origin/main HEAD` prints a TREE id (exit 0 = no conflicts). You cannot `git worktree add` or checkout that id directly ('invalid reference'). Wrap it first: `C=$(git commit-tree <tree> -p origin/main -p HEAD -m tmp)`, then `git worktree add --detach /tmp/x $C`, symlink node_modules into it, run the targeted tests, and `git worktree remove --force`. Also check the PR's headRefOid against HEAD before reviewing: a reused scratch worktree may be left on another branch's commit.
