All tutorials

Tutorial 1 of 8

Why Version Control?

See why developers save work as a chain of snapshots, and how Git keeps that chain for you.

About 5 minutes

What you will be able to do

  1. Explain the problems version control solves: lost work, confusing file copies and team edits.
  2. Describe a commit as a snapshot of the whole project, with a message, an author, a time and a parent.
  3. Read a simple commit graph: commits, parent links, the main label and HEAD.
  4. Tell Git (the tool) apart from GitHub (a hosting website).

Title

Why Version Control? Save points for your code.

This tutorial shows why developers track changes and how Git records them as a chain of snapshots.

The problem

report_final, report_final2, report_REAL_final... Which one works? Who changed what, and why?

Copying files by hand soon gets confusing, especially when a teammate edits the same work.

What version control does

Version control records every saved change: what changed, who changed it, when, and why.

A version control system keeps a history of changes, so you can compare, go back and work as a team.

Analogy: game save points

Like save points in a game: reach a safe spot, save, and you can always come back.

Think of each commit as a save point you choose to create, which you can return to later.

The analogy, and where it breaks

A game save point lets you return to a safe moment. A Git commit is a save point for your project.

Git never saves on its own, so you choose when to save, and each save captures the whole project, not just where you are standing.

Save points become commits

In Git, a save point is called a commit. Each commit links back to the one before it.

Commits form a chain where each new commit points back to its parent, and that chain is your project history.

What is inside a commit

A commit stores a snapshot of all tracked files, plus the author, date, message and a link to its parent.

Each commit records the full state of your tracked files along with who made it, when, why and which commit came before.

Commit IDs

Every commit gets a unique ID, a long code of letters and numbers. We usually type just the first few characters.

Git names each commit with a unique ID, and a short prefix of that ID is usually enough to point at it.

The repository and the main label

A repository is your project plus its history. main labels the newest commit, and HEAD shows where you are now.

The repository keeps every commit in a hidden .git folder, the main label moves to each new commit, and HEAD marks your current position.

Git is not GitHub

Git is the tool on your computer. GitHub is a website that hosts Git repositories and adds teamwork features.

Git works fully offline on your computer, while GitHub is one of several websites where you can store and share Git repositories.

Recap

Commits are save points you choose. Each is a full snapshot with a message. The chain is your history.

{"commits": [{"id": "C1", "parents": []}, {"id": "C2", "parents": ["C1"]}, {"id": "C3", "parents": ["C2"]}], "refs": [{"name": "main", "target": "C3", "kind": "branch"}], "head": {"ref": "main"}}

Version control gives you save points for the whole project, and the next tutorial shows how to make your first one.

Check yourself

0 of 4 answered

Check 1 of 4

What does one Git commit record?

Check 2 of 4

You edited three files and saved them in your editor, but never ran git commit. Do you have a Git save point for these edits?

Check 3 of 4

Click the commit you are on right now.

C1C2C3HEAD: main

One branch: C1, then C2, then C3. The main label and HEAD are both on C3.

Check 4 of 4

Which statement about Git and GitHub is true?

git --version                       # check that Git is installed

# One-time setup (skip if you have done this before)
git config --global user.name "Your Name"
git config --global user.email "you@example.com"

# A throwaway practice repo
mkdir -p ~/git-practice/t01-saves
cd ~/git-practice/t01-saves
git init -b main

echo "Level 1 cleared" > progress.txt
git add progress.txt
git commit -m "Save point 1"

echo "Level 2 cleared" >> progress.txt
git add progress.txt
git commit -m "Save point 2"

git log --oneline                   # two commits, newest first (press q if a pager opens)