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.
3 points to say:
- Blob, tree, commit are all objects addressed by hash; an unchanged file reuses the old blob.
- A commit stores a snapshot, not a diff; deltas in packfiles are only a storage optimization.
- 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.