Log inStart free
LESSON 1.17 · 6 STAGES · 3 CONTROLS · 3 CHECKSPRO · PREVIEW

Git's object model

Watch Git store each file by its hash, and see branches move as pointers.


Pro lesson. Stage 1 is free to watch. Pro opens all 6 stages, 3 controls and 3 checks, in this lesson and every other.

Go Pro · $8.25/mo
EXPLAINER · 1.17 · REPO BAYOBJECTS 0 · HEAD → main · main: no file
01
Stage 1 of 6 · Make a repository
git init makes a repository: a .git folder for objects, refs and HEAD. HEAD names main, but main has no commit yet.
Explain it simply

Your project folder, toy, holds two files. git init adds a hidden folder, .git, and that's the repository. It will keep every saved version, plus small files that name them. HEAD says which branch you're on. It names main, but main has no file yet, because nothing is saved.

The working tree holds docs/notes.txt and hello.py. The .git folder has no objects. HEAD holds ref: refs/heads/main, and refs/heads/main does not exist.

file bytes, blobtree, commit, tag objectid, pointer, refwritten in this stageno file yet
working treetoy/.git/objects.git/refsblobstreescommits, tagsterminal$ git init -b mainInitialized empty Git repository in /home/ada/toy/.git/# .git/HEAD = ref: refs/heads/maindocs/notes.txtRun hello.py.hello.pyprint("hello")HEAD→ main21 Bmainheads/no fileworking treetoy/.git/objects.git/refsblobstreescommits, tagsterminal$ git init -b mainInitialized empty Git repository in /home/ada/toy/.git/# .git/HEAD = ref: refs/heads/maindocs/notes.txtRun hello.py.hello.pyprint("hello")HEAD→ main21 Bmainheads/no file
Toy: 2 files · real Git ids (SHA-1) · loose objects only · the index is not drawn
STAGE 1 / 6
MATH · STAGE 1HOVER A SYMBOL OR A SHAPE
repository=objects+refs+HEAD\sy{repo}{ink}{\text{repository}} = \sy{obj}{data}{\text{objects}} + \sy{refs}{param}{\text{refs}} + \sy{head}{param}{\texttt{HEAD}}
HEAD=ref: refs/heads/main;objects=0\sy{head}{param}{\texttt{HEAD}} = \texttt{ref: refs/heads/main};\quad \sy{obj}{ink}{\text{objects}} = 0

A repository is a store of objects plus refs that name them.

Common mix-ups

MYTHA commit stores only the lines that changed.

The fix, and 1 more mix-up with the diagram to show them, come with Pro.

Predict, then reveal
3 CHECKS · PRO
Q01With notes.txt edited, how many new objects do the edit and the commit write?

Make your guess, then test it in the diagram. All 3 checks come with Pro.

PRO LESSON · YOU WATCHED STAGE 1 OF 6
Unlock the full explainer
  • 5 more stages and 3 live controls
  • 2 mix-up cards and 3 predict-then-reveal checks
  • Watch it as a narrated video, in three voices
  • Every Pro lesson and capstone · 656 in total

$99 a year, or $15 a month. Cancel any time.