What is a Git tree object?

Definition

A Git tree object maps directory entries to other objects. File entries reference blobs, while directory entries reference additional trees, forming a hierarchy rooted at a commit.

Trees are immutable and content-addressed. A change to one file produces new objects along the affected path while unchanged subtrees can be reused.

ELI5

A Git tree object represents one directory by listing names, file modes and identifiers for blobs or nested trees. These links build the folder hierarchy stored by a commit.

For example, changing one file creates a new blob and new tree objects along that file's path, while unchanged folders can reuse their earlier trees. The tree is identified by its contents and does not change in place.

What information does a Git tree store?

It stores entry names, file modes, object types and object IDs for blobs, nested trees or submodule commits.

How is a Git tree different from a directory on disk?

A tree is an immutable repository object describing a snapshot, while a working directory is a mutable filesystem view.

  1. Why Git Hosting Is Hard beside a flat diagram of replicated repository servers and a latency bottleneck
Definition card for Git tree object: What is a Git tree object?

A Git tree object represents a directory by listing file names, modes and object IDs for blobs or nested trees.