SteelReed

Search

Search posts, questions…

DevOps & CloudQuestion 1 / 35

Junior

How does Git store data? What are a commit, a branch, the staging area and HEAD really?

Short answer

Git is a content-addressed object store: a blob holds file content, a tree lists a directory, a commit points to a root tree plus parents. A branch is just a small file holding the hash of the latest commit; HEAD points to the current branch.

parentHEADrefs/heads/maincommit c2commit c1root treeblob: file content

3 points to say:

  1. Blob, tree, commit are all objects addressed by hash; an unchanged file reuses the old blob.
  2. A commit stores a snapshot, not a diff; deltas in packfiles are only a storage optimization.
  3. A branch is a pointer, HEAD points to a branch; in detached HEAD, new commits need a branch or gc will clean them up.

Keep reading the deep dive

Create a free account to read the full explanation and follow-up questions, mark questions as studied and review them on a schedule.