Lesson
Git fundamentals
The mental model: repository, working directory, staging area, commits, branches, and HEAD.
Learning objectives
- Describe the three areas Git works with
- Explain what a commit actually stores
- Understand branches and HEAD as pointers
Git is a graph of snapshots
Git does not store diffs as its primary model — it stores snapshots. Every commit captures what all your files looked like at that moment. Commits link to their parents, forming a directed acyclic graph (DAG) that is your project's history.
Three areas
The working directory is what you edit on disk. The staging area (index) is where you assemble the next commit. The repository is the committed history. git add moves content from the working directory to staging; git commit moves it from staging into the repository.
Branches and HEAD are pointers
A branch is a movable pointer to a commit — nothing is copied when you create one. HEAD is a pointer to the commit you have checked out, usually by pointing at a branch. When you commit, the branch moves forward and HEAD comes along for the ride.
Try it yourself
Empty folder
Run git init to create a repository.
Working directory
Clean — no uncommitted changes.
Staging area
Nothing staged. Run git add.
Repository
No commits yet.
Initialize a repo and make your first commit. Watch the commit node appear and main move.
Commands used
git init
git add app.ts
git commit -m "feat: first commit"
git log --onelineCommon mistakes
- • Thinking git tracks folders — Git tracks file content, and empty folders are not stored.
- • Believing a commit only saves changed files — it references a full snapshot (reusing unchanged content).
Best practices
- • Commit small, logical units of work.
- • Run git status often to stay oriented.
Mini challenge
Create a repository, add two files, and make a single commit that includes both.
Open the visualizer to try itSummary
- Commits are snapshots linked into a graph.
- Working directory → staging → repository.
- Branches and HEAD are cheap, movable pointers.