Skip to content
Optimal Lab

DevOps · interactive

How Git stores history

Git is a store of objects named by the hash of their content: blobs for file contents, trees for folders, commits for snapshots. Branches are just names pointing at commits. Step through a few commands.

$ git init

HEAD → main

Commits

  • none

Trees

  • none

Blobs

  • none

0 objects · highlighted: written by this command (0)

An empty repository: no objects yet, and main doesn't point anywhere.

command 1 of 6
  1. 1

    Git hashes each file's content and stores it once. Same content, same hash, same object.

    git cat-file -p <hash>

  2. 2

  3. 3

  4. 4

In production

Tools and technologies

Every Git host stores the same content-addressed objects.

Not tied to one language — use these names when you search docs or design a system.