Module 1: Advanced Mental Model and Lab Setup
Git Objects, Refs, HEAD, and the Commit Graph
Git Objects, Refs, HEAD, and the Commit Graph
Module: Module 1: Advanced Mental Model and Lab Setup
Git is a content-addressed database plus a set of movable names. The database stores blobs, trees, commits, and annotated tags. Refs such as branches and tags give human-friendly names to object IDs. HEAD tells Git what you currently have checked out, usually by pointing at a branch ref.
A blob stores file content but not the file name. A tree maps names to blobs and nested trees. A commit points to one tree, records parent commits, and stores metadata such as author, committer, and message. This structure explains why branches are cheap: creating a branch is just creating another ref that points at an existing commit.
Once you understand refs, commands like branch, reset, merge, rebase, and tag stop feeling magical. Most advanced Git work is careful movement of refs while preserving or intentionally rewriting reachable commits. The commit graph is the source of truth; the working tree is only one checkout of one point in that graph.
Command Walkthrough
mkdir advanced-git-lab && cd advanced-git-lab
git init
printf 'hello\n' > app.txt
git add app.txt && git commit -m 'Add initial app text'
git cat-file -t HEAD
git cat-file -p HEAD
git rev-parse HEAD
git show --stat --oneline HEADcommit d4e5f6a7b8c9
Author: Alex Engineer <[email protected]>
Add focused change
app.conf | 2 +-Hands-on Lab
Create two commits, then inspect each commit object with git cat-file. Draw the relationship between commit, tree, and blob in a notes file. Commit the notes as 'Document Git object model'.
What to Watch For
- Do not confuse a branch with a folder of files. It is only a ref pointing at a commit.
- A commit hash identifies content and metadata. Changing the message creates a different commit ID.
- Detached HEAD is not an error by itself; it means HEAD points directly at a commit instead of a branch.
Completion Check
You should be able to explain what each command changed, inspect the resulting history, and describe how you would undo or recover from the operation before using it in a shared repository.