Git and Professional Development Workflow

How Git Actually Works

Commits, the three areas, branches, and the reflog

13 min read · Lesson 13 of 18

Git Is Not What You Think

Most developers learn Git as a set of commands: add, commit, push, pull. When something goes wrong, they panic because they don't understand the underlying model. Once you understand how Git actually works, every command becomes intuitive and recoverable.


Commits Are Snapshots, Not Diffs

A common misconception: commits store the changes you made. Wrong. Each commit stores a complete snapshot of every tracked file at that moment.

Git is efficient about this — if a file hasn't changed, the commit stores a pointer to the previous version rather than a copy. But conceptually, each commit is a full snapshot of your project. This is why operations like checkout and reset are so fast — Git isn't replaying changes, it's restoring snapshots.

Each commit contains:

  • A reference to a tree (the snapshot of all files)
  • A pointer to the parent commit(s)
  • Author, committer, timestamp, and message
  • A unique SHA-1 hash (like a3f8c2d)

The Three Areas

Git has three areas where your files live:

  1. Working Directory — Your actual files on disk. What you see in your editor.
  2. Staging Area (Index) — A preview of what your next commit will contain. Files go here when you git add.
  3. Repository — The committed history. Files go here when you git commit.

This three-stage model is why you can selectively commit. Edit 5 files, git add only 2 of them, commit — the other 3 remain modified but uncommitted. This enables clean, focused commits.


Branches Are Just Pointers

A branch is nothing more than a pointer to a commit. When you create a branch, Git creates a 41-byte file containing a commit hash. That's it.

HEAD is a special pointer that tracks which branch you're currently on. When you commit, the current branch's pointer moves forward to the new commit, and HEAD follows along.

This is why branches are cheap in Git — creating 100 branches adds essentially zero overhead. It's just 100 tiny files pointing at commits.


The Reflog: Your Safety Net

The reflog records every time HEAD moves. Even if you delete a branch, reset to a previous commit, or make a mistake, the reflog remembers where you were:

git reflog
# a3f8c2d HEAD@{0}: commit: Add user authentication
# b7e9f1a HEAD@{1}: checkout: moving from feature to main
# c4d2e3f HEAD@{2}: commit: Fix navigation bug

If you accidentally reset and lose commits, git reflog shows the commit hashes. You can recover with git checkout <hash> or git reset --hard <hash>.

The reflog is local-only and expires after 90 days by default. It's your personal undo history — use it fearlessly when something goes wrong.

Key Takeaways

  • Commits are snapshots, not diffs. Each commit is a full picture of your project.
  • The three areas (working → staging → repository) enable selective commits.
  • Branches are pointers to commits. They're lightweight and cheap.
  • The reflog records every HEAD movement. Almost nothing in Git is truly lost.
Ask about this lesson