Git Internals: a Quick Intro
Tested 2026-11-26 on macOS 14.1, Apple M3 Pro; no containers or VMs · with git 2.39.3 (Apple Git-146), Python 3.12.9 · by Vivek Sahu (@viv1) · CC BY 4.0
You’ve just spent an afternoon on three commits.
Then a git reset --hard HEAD~2 on the wrong branch, and git log shows one commit.
The work isn’t gone. Both commits are still in .git; the only thing in your history that changed is a 41-byte file, the branch.
Git also kept a log of where that branch has been, and one command puts it back.
This course is for people who use git every day and want to know what’s underneath. You’ll open .git, build
commits by hand with git’s low-level commands, then lose work in the ways it really gets lost and get it back.
By the end you’ll be able to:
- say what a commit, a tree and a blob are on disk, and predict an object’s id before git prints it;
- explain what a branch, HEAD and the reflog are, and what
reset,switchandbranch -Dchange; - find and recover commits after a bad reset, a deleted branch or a dropped stash, and work you only
git added; - tell when lost work really is gone, and what removes it.
How it works
Each lesson starts with an animated, step-by-step picture (press Play, or step with the arrow keys), then
explains with real output, with optional Go deeper sections. Each practical has you type the commands
yourself in ~/git-internals-intro/: requirements, a hint, a hidden solution, a “predict first” question and a part
where you break it on purpose. One script, ./lab, does the rest:
./lab setup pNchecks what a practical needs (git 2.28 or newer). It creates nothing for you: every repository in this course you make yourself../lab check pNtells you whether your repository is right. It only runs read-only git commands, each one written tolab.log../lab reset pNstarts you at a practical with the earlier ones’ solutions replayed. It asks first, and moves your repositories into a new folder rather than deleting them.
All you need is git and python3 (for ./lab) on your own computer (macOS or Linux). No containers.
Path
| Lesson | Practical | You’ll be able to |
|---|---|---|
| 1 · Where a commit actually lives | read any object with cat-file; say why the same content always has the same id | |
| 2 · Branches are just files | 0 · A commit with no git commit | build commits from blobs and trees by hand; write a branch with update-ref and read its reflog; find a corrupted object |
| 3 · Getting lost work back, and when it really is gone | 1 · Capstone: the rescue | recover work lost four ways, and know when gc makes it unrecoverable |
What your folder will look like
~/git-internals-intro/
├── lab the lab script: setup, check, reset (from Practical 0)
├── lab.log every command ./lab ran, with its output
├── byhand/ Practical 0: a repository whose commits you built with plumbing commands
├── blob-backup Practical 0: your copy of the blob you corrupt
├── rescue/ Practical 1: a repository you lose work in, four ways, and recover
└── doomed-id Practical 1: the id of the commit gc destroys