How it works · version control system
How Git works
Every version of every file is stored under a name made from its own contents, and a commit is a small note pointing at a whole snapshot.
Think of it like this. A warehouse where every box is labelled with a fingerprint of what is inside. Two identical boxes get the same label, so only one is kept.
- ⌨️ The command Looks up the word after “git” in a table and runs that command’s code. git.c
- 📦 The object store Saves file contents, folders and commits, each named by a hash of its contents. object-file.c
- 📋 The index The staging area: the list of what the next commit will contain. read-cache.c
- 🔖 Refs Branches and tags. Each is just a name that points at one commit. refs.c
- 🗜️ Packfiles Squeezes many objects into one file, storing similar ones as differences. packfile.c
- 🔀 Diff and merge Works out what changed between two snapshots, and combines two lines of work. merge-ort.c
Follow one thing through: git add notes.txt, then git commit
- git finds “add” in its table of commands and runs it.git.c
- The file’s contents are hashed, compressed and saved as an object named by that hash.object-file.c
- The index now says: notes.txt is that object.read-cache.c
- On commit, the index is written out as tree objects, one per folder.builtin/commit.c
- A commit object is made: this tree, this parent commit, this author, this message.commit.c
- The current branch is moved to point at the new commit.refs.c
The clever bit: The name is the contents
Git never asks “which version is this file?”. It hashes the contents and uses the hash as the name. The same contents always give the same name, so an unchanged file costs nothing to commit again. A commit’s name covers its tree and its parent, so changing anything in history changes every name after it. That is why history can’t be quietly edited.
Words you’ll meet
- blob
- The contents of one file, with no name attached.
- tree
- One folder: a list of names, each pointing at a blob or another tree.
- commit
- A snapshot: one tree, its parent commits, who made it and why.
- ref
- A name, like main, that points at a commit.
Good questions to ask next
- What is HEAD?
- What does a merge actually do?
- Why is a branch cheap to make?
Open Git in Bento and ask them there. It reads the project in your browser, draws its parts as a map you can press, and opens the real code behind each one.
Take Git apart yourself.
Free and open source. Nothing to install, no account.
Ideas inside it
More projects, taken apart
Written by hand from the code as it was on 2026-11-30 (commit 566b699). Git belongs to its authors; this page is an independent explanation. Spot a mistake? Tell us.