Earn it: GitHub Achievements Academy home

Git 1: How Git actually works

Most Git confusion comes from one missing picture. Once you can see what Git is storing, commands stop feeling like spells. This lesson has no commands to memorize, just the model that makes the rest easy.

A commit is a snapshot

A commit isn't a list of changes. It's a snapshot of your whole project at one moment, plus:

  • who made it, and when
  • a message saying why
  • a pointer to its parent commit (the one before it)

Every commit gets an ID, a long hash like 3f9c2a1e…. You'll usually see the first 7 characters. The hash comes from the commit's contents, so if anything changes, the ID changes. That's why Git history is so hard to tamper with silently.

Because each commit points to its parent, your history forms a chain:

Three commits. Each one points back to the one before it.Try this in the sandbox

Git doesn't waste space storing the same file twice. If a file didn't change between snapshots, both commits point to the same stored copy.

A branch is just a label

This is the big one. A branch is not a copy of your code. It's a tiny file containing one commit ID, a movable label that says "this commit is the tip of main".

The main label points at commit C, the tip of the branch.Try this in the sandbox

When you commit on main, Git makes commit D and moves the main label forward to it. Creating a branch just adds a second label:

After git branch feature, two labels sit on the same commit. Nothing was copied.Try this in the sandbox

That's why making a branch is instant, even in a huge project.

HEAD is "you are here"

HEAD tells Git which branch you're currently on. When you run git switch feature, HEAD moves to point at feature, and your files change to match that branch's snapshot. New commits move whichever branch HEAD points at.

If HEAD points straight at a commit instead of a branch, Git calls that a detached HEAD. It's safe to look around, but commits you make there aren't on any branch. See the "Oh no" guide if you end up there.

After git switch --detach B and one commit, HEAD sits on X, which no branch points to yet.Try this in the sandbox

The three places your work lives

PlaceWhat it isCommands that move work here
Working treeThe files you see and edit(you, editing)
Staging area (also called the index)What will go into your next commitgit add
RepositoryThe saved history of commitsgit commit

The staging area is what lets you commit part of your work. You can fix a bug and a typo in the same session, then commit them separately with clear messages.

Local vs. remote

Your laptop holds a full copy of the repository, with every commit and every branch you've fetched. GitHub holds another copy. They only sync when you tell them to:

  • git fetch / git pull bring commits down from GitHub
  • git push sends commits up to GitHub

Git also keeps read-only labels like origin/main. They record where main was on GitHub the last time you fetched.

Try it: see the model for yourself

git log --oneline --graph --all --decorate

You'll see commits as a graph, with branch labels (main, origin/main, HEAD -> main) attached to commits. Make a branch and look again:

git switch -c try-labels
git log --oneline --graph --all --decorate

Both labels sit on the same commit. Nothing was copied.

No repo handy? Try the first sandbox challenge in your browser and watch commits and labels move as you type.

This command is so useful that most people make a shortcut: git config --global alias.lg "log --oneline --graph --all --decorate" Now git lg shows the graph.

What you learned

  • Commits are snapshots that point to their parents
  • Branches are movable labels, and HEAD is "you are here"
  • Work moves from the working tree to the staging area to the repository
  • Your copy and GitHub's copy only sync when you fetch, pull or push

Next: Git 2: The everyday loop

Check what you learned

1. What is a branch in Git?
2. What does HEAD tell Git?
3. Which command moves changes into the staging area?

Show the answers
  1. A movable label pointing at one commit: That's why creating a branch is instant, even in huge projects.
  2. Which branch or commit you're on right now: HEAD is "you are here". New commits move whichever branch HEAD points at.
  3. git add: git add stages changes. git commit saves what's staged into history.

Your progress is saved in this browser only.

Last reviewed November 2026. Improve this page on GitHub. Every fix you send counts toward Pull Shark.