Journeys · Git · L0
git add and git commit
One new file, from your working tree to the index, into three objects, and onto main.
✓ Validated on Git 2.43.0 · Run 1 · 2026-11-21Preview
The 30-second answer
git add reads the file, stores its content as a blob object and writes the blob's id into the index. git commit turns the index into trees, one per folder, and writes a commit object that names the top tree, the parent commit, you and the time. Then it moves main to the new commit. HEAD still says "ref: refs/heads/main", so you are on the new commit too. Every object's name is the hash of its content: the same file, folders and clock give the same ids on any machine.
Mental model
A library archive. You write a page at your desk. At the counter, the clerk files a copy of the page in the archive, under a number made from its words, and notes the number on a catalogue card. When you commit, the clerk files the catalogue itself, plus a cover sheet with your name, the time and the previous edition's number. Then the clerk moves the bookmark for the latest edition to the new cover sheet.
Where the analogy breaks
A real archive numbers pages in order. Git names each object by a hash of its content, so two equal pages share one file, and an unchanged folder keeps its old number. And the bookmark is a plain text file holding 40 characters.
Press play and watch the story unfold.
Event stream
Click a row to inspect it| # | Time | From → To | Kind | What |
|---|---|---|---|---|
| Press play. Each hand-off appears here, like a packet capture. | ||||
Predict, then check
You run git add README.md again without changing the file. How many new objects appear?
None. The content is the same, so the blob id is the same, and that object exists already. The last step shows count: 21 again.
You build a second Explorer repo and make the same commit with the same clock. Which commit id do you get?
8eab18c again. The tree, the parent, the names and the dates are the same, so the hash is too. Journeys 2 and 4 do exactly that.
Transcript
The whole journey as text, for reading, searching and screen readers.
Your clone before you start
Your clone is on main, level with origin/main, and nothing is changed. The file .git/HEAD holds one line: "ref: refs/heads/main". HEAD names a branch, and the branch names a commit, 7a05869. The object store holds 18 loose objects, one file each, and no pack.
Insight: A clone from a local path does not use Git's transfer protocol. It copies the files under .git/objects, as hardlinks when it can. So your fresh clone holds loose objects, not a pack.
git→working tree: git status: nothing to commitgit→refs and HEAD: HEAD → refs/heads/main → 7a05869git→refs and HEAD: main is 7a05869git→object store: 18 loose objects, 0 in packs
A new file in the working tree
You write one line into README.md. git status lists it with "??": untracked, not in the index. git hash-object computes the id Git would give its content, 6123a6f, without storing anything. Asked for that object, git cat-file finds nothing: it is not in the object store yet.
Insight: The id comes from the content alone. Anyone who writes the same 15 bytes gets 6123a6f, before Git has stored anything.
git→working tree: README.md writtengit→working tree: ?? README.md: untrackedgit→git: its blob id would be 6123a6fgit→working tree: 15 bytesgit→object store: not in the object store yet
git add: a blob and an index entry
git add prints nothing. It stored the content as a blob and recorded it in the index, the file .git/index. git ls-files -s lists the index: mode, blob id, stage number and path, one line per file. README.md sits next to the three api files that came with the clone. The object store grew from 18 to 19, and the new file's path is the id split after two characters.
Insight: git add, not git commit, copies your file into Git. Edit README.md now and the index still holds the version you added.
git→object store: git add README.md: blob storedgit→index: index entry: 100644 6123a6f 0 README.mdgit→index: A README.md: stagedgit→object store: 19 loose objects
git commit: a tree and a commit
git commit prints the branch and the new commit's short id: "[main 8eab18c] Add a README". The object store grew from 19 to 21. The new files are a tree, 70cd770, and the commit, 8eab18c. The blob 6123a6f is not written again: git add stored it already.
Insight: Three new objects for one file: its blob, the top folder's tree and the commit. The api folder did not change, so its tree is not written again.
git→object store: [main 8eab18c] Add a READMEgit→object store: 21 loose objectsgit→object store: blob 6123a6f, tree 70cd770, commit 8eab18cgit→object store: what each new id is
Inside the three objects
The commit names its tree, its parent 7a05869, the author and the committer, then the message. The time is stored as 1793854800, in seconds since the Unix epoch, plus the zone +0530. git log turns it back into "Thu, 5 Nov 2026 10:30:00 +0530": the clock you exported. The tree lists README.md as a blob and api as a tree, 9a97129. The parent commit's tree points at the same 9a97129: the folder did not change, so both commits share it. The blob holds the line you wrote, nothing more.
Insight: A commit holds the whole snapshot, not a diff: one top tree. Unchanged folders cost nothing, because the new tree points at their old trees.
git→object store: commit 8eab18c: tree, parent, author, committergit→object store: author and committer date: your clockgit→object store: tree 70cd770: README.md and apigit→object store: the parent's tree: the same api treegit→object store: the blob: your line
main moves; HEAD follows
.git/HEAD did not change: it still names refs/heads/main. The file .git/refs/heads/main now holds 8eab18c. Your remote-tracking ref origin/main still holds 7a05869: nothing left your clone. The reflog records the move, "commit: Add a README". git status says you are ahead of origin/main by one.
Insight: A branch is a file with one commit id in it. Committing writes the objects first and moves the branch last.
git→refs and HEAD: HEAD: still ref: refs/heads/maingit→refs and HEAD: refs/heads/main: 8eab18cgit→refs and HEAD: origin/main still 7a05869refs and HEAD→reflog: HEAD@{0}: commit: Add a READMEgit→refs and HEAD: main...origin/main [ahead 1]git→object store: add the same file again: still 21
Go deeper
- Pro Git, 10.2 Git Internals: Git Objects
- Pro Git, 10.3 Git Internals: Git References
- git-commit: commit information (GIT_AUTHOR_DATE, GIT_COMMITTER_DATE)
- git-commit: date formats (Git internal format: seconds since the Unix epoch and a zone)
- git-hash-object
- git-clone: --local
- git-count-objects
- gitglossary: index, working tree, ref, symref
- gitrepository-layout: objects, refs, HEAD, logs