SkillNavora
Git & GitHub Complete Guide › Lesson 1 of 8 · about 18 minutes
Lesson 1

How Git works: snapshots, commits, branches and the three areas

The mental model that makes every Git command make sense: snapshots instead of differences, the working folder, staging area and repository, what a commit really contains, and why a branch is only a pointer.

Checked against official sources in November 2026. Lessons build on each other.
In plain words. Git is a camera for your project folder. Each commit is a photo of every file at that moment, with a caption and a link to the previous photo. A branch is a sticky note that says "we are here" on one photo, and it moves forward each time you take a new one.

Key ideas

Repository (repo)A project folder plus its full history, stored in a hidden .git folder.
CommitA saved snapshot of the whole project, with an author, date, message and a link to its parent commit.
Working treeThe files you see and edit.
Staging area (index)The list of changes you have chosen for the next commit.
BranchA movable name that points to one commit. HEAD tells Git which branch you are on.
Git vs GitHubGit is the free tool on your computer. GitHub is a website that hosts Git repositories and adds pull requests, issues, Actions and more.

How it works

1. Snapshots, not differences

Most people imagine Git stores a list of changes. It actually stores snapshots: each commit points to a full picture of the project. Files that did not change are not copied again; Git simply points to the same stored content. That is why switching branches is fast and why history is reliable.

Every piece of stored content gets an ID (a hash) calculated from the content itself, like 5e9b349. If even one character changes, the ID changes, so history cannot be quietly edited.

2. The three areas

AreaWhat it isCommands that move things
Working treeYour files on diskedit files; git restore to undo edits
Staging areaChanges chosen for the next commitgit add to stage; git restore --staged to unstage
RepositorySaved commits in .gitgit commit to save; git log to view

Staging lets you commit only part of your work: fix two bugs, then save them as two clean commits.

3. Look inside a real commit

These commands show what Git actually stored for the first commit of a small notes project. A commit points to a tree (the folder), the tree points to blobs (file contents), and the branch file simply holds the latest commit's ID.

Real terminal output (captured when this guide was built)
$ git cat-file -t HEAD
commit
$ git cat-file -p HEAD
tree ab39980f441eabb3f33aa3ba8c6846a18da78113
author Asha Learner <[email protected]> 1793594280 +0530
committer Asha Learner <[email protected]> 1793594280 +0530

Add README with the course title
$ git cat-file -p HEAD^{tree}
100644 blob c4302146ff40c2cbd6dabd9dec8498f32cdb086a	README.md
$ git cat-file -p HEAD:README.md
# My study notes
$ cat .git/HEAD
ref: refs/heads/main
$ cat .git/refs/heads/main
5e9b349eb22b7a59f77c79d033ec8e6a0a593b65

4. Branches are just pointers

  • main is a file in .git that contains one commit ID. A new commit on main moves that pointer forward.
  • Creating a branch creates a new pointer to the same commit. It costs almost nothing, so make branches freely.
  • HEAD is Git's "you are here". Normally it points to a branch (ref: refs/heads/main).
  • Merging joins two lines of history; when one branch is simply ahead, Git just moves the pointer (a fast-forward).

5. Where GitHub fits

Your computer has the complete repository. GitHub keeps another copy (a remote, usually called origin) so you can back up, share and collaborate. You push commits up, and fetch or pull other people's commits down. Pull requests, reviews, issues and Actions are GitHub features built around that shared copy.

Common mistakes and fixes

MistakeFix
Thinking GitHub and Git are the sameGit runs on your computer and works offline; GitHub hosts copies and adds collaboration tools.
Being afraid of branchesThey are just pointers; create one for every change.
Committing everything at the end of the weekCommit small, logical steps with clear messages.

Practice

  1. Draw the three areas on paper and write which command moves a change between each.
  2. In a test repository run git cat-file -p HEAD and find the tree, author and message.
  3. Explain to a friend why a branch costs almost nothing to create.

Quick check

Does Git store differences or snapshots?

Snapshots: each commit points to a full picture of the project; unchanged files are reused, not copied.

What does the staging area hold?

The changes you have chosen to include in the next commit.

What is inside .git/refs/heads/main?

The ID (hash) of the latest commit on main.

What is HEAD?

Git's pointer to where you are, normally the current branch.

Go further (official sources)

Refer & earn