Synopsis
git commit-tree <tree> [-p <parent>]... [-m <msg>] [-S]
Description
The git commit-tree command builds a commit object from a given tree SHA, an optional list of parent commits, and a message. It outputs the new commit's SHA. Unlike git commit, it does NOT update any ref — the resulting commit is dangling until you point a branch or tag at it.
In day-to-day use, git commit-tree integrates closely with shell aliases, editor plugins, and continuous integration. Power users often add aliases that combine flags they always pass, or wrap the command in scripts that enforce team conventions. Output formatting can be customized via Git config — pretty formats, color schemes, and pager behavior are all tunable. When something goes wrong, the first diagnostic step is usually to re-run the command with GIT_TRACE=1 in the environment, which reveals the underlying plumbing calls. For unusual situations, the --help output (git commit-tree --help) opens the full manual page with details on every option, including those rarely used in casual workflows but essential for debugging or scripting at scale.
Understanding how git commit-tree interacts with the rest of Git's data model — the object database, the index, refs, and the working tree — pays dividends. Each command operates on some subset of these pieces, and knowing which it touches helps predict outcomes and recover from mistakes. Reading the official Git documentation alongside hands-on practice in a throwaway repository is the fastest way to internalize the nuances. Most production issues with Git stem from one of three causes: surprising default behavior, partial network operations, or rewriting history that was already shared. A working mental model of git commit-tree's side effects helps avoid all three.
When to Use
Most developers never use this directly. It's a building block for tools that synthesize commits programmatically: importers, custom merge strategies, history-rewriting tools. filter-repo uses commit-tree internally.
Common Options
| Option | Description |
|---|---|
-p <parent> | Specify a parent commit (repeatable for merges). |
-m <msg> | Commit message (or read stdin). |
-F <file> | Read message from file. |
-S[<keyid>] | GPG-sign the commit. |
Examples
TREE=$(git write-tree)
COMMIT=$(echo "Initial commit" | git commit-tree "$TREE")
git update-ref refs/heads/main "$COMMIT"
# Build a root commit from scratch
PARENT=$(git rev-parse HEAD)
TREE=$(git write-tree)
COMMIT=$(echo "Custom merge" | git commit-tree "$TREE" -p "$PARENT" -p "feature")
git update-ref refs/heads/main "$COMMIT"
# Synthesize a custom merge commit
Common Mistakes
Forgetting to git update-ref leaves the commit dangling — git gc will eventually delete it. Author/committer environment variables (GIT_AUTHOR_NAME etc.) must be set if you want non-default identities.
Related Commands
git write-tree, git update-ref, git commit, git filter-repo