Lesson 1 • Beginner
Introduction to Version Control 🌿
By the end of this lesson you'll understand why version control exists, configure Git for the first time, and create your own repository with its first commit — the foundation every developer builds on.
What You'll Learn in This Lesson
- Explain what version control is and why every developer relies on it
- Describe how Git stores history as snapshots you can return to
- Move changes through Git's three areas: Working Directory → Staging → Repository
- Set your identity once with first-time git config (user.name and user.email)
- Use git init, git add, git commit, git status and git log confidently
- Create a brand-new repository and make its very first commit
1️⃣ What is Version Control?
Version control is a system that records changes to your files over time so you can review them, undo them, or work on them with other people. Without it, you end up with folders full of final_v2_ACTUALLY_FINAL.zip files. Git — created by Linus Torvalds (the creator of Linux) in 2005 — is the world's most popular version control system. It's distributed, meaning every developer keeps the project's full history on their own machine. A commit is a saved snapshot of your project, and the log below is a history of those snapshots.
# See the history of a real Git repository.
# Every commit records who changed what, and when.
git log --oneline --pretty="%h %ad %an %s" --date=shorte5f6g7h 2024-01-17 Bob Update color scheme
d4c3b2a 2024-01-15 Charlie Add footer links
c3d4e5f 2024-01-14 Alice Fix mobile layout
b2c3d4e 2024-01-12 Bob Add navigation bar
a1b2c3d 2024-01-10 Alice Create homepage2️⃣ Installing & Configuring Git
Git runs on every operating system. After installing, do the one-time setup: tell Git your name and email. Git stamps these onto every commit you make so your team (and future you) knows who changed what. The --global flag means you set them once for your whole machine, not per project.
# --- Install Git (pick the line for your OS) ---
# Windows: winget install Git.Git (or download from git-scm.com)
# macOS: brew install git (or: xcode-select --install)
# Ubuntu/Debian: sudo apt update && sudo apt install git
# Fedora: sudo dnf install git
# Verify the install
git --version
# First-time setup (required) — attached to every commit you make
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
# Recommended defaults
git config --global init.defaultBranch main
git config --global color.ui auto
# Check what you've configured
git config --listgit version 2.43.0
user.name=Your Name
user.email=you@example.com
init.defaultBranch=main
color.ui=autoNow finish the setup yourself. Replace each ___ using the 👉 hint, run the commands, and check your output against the Output panel.
# 🎯 YOUR TURN — finish the first-time setup, then run it in your terminal.
# Git stamps every commit with the name + email you set here.
# 1) Set your display name
git config --global user.name ___ # 👉 your name in "double quotes", e.g. "Ada Lovelace"
# 2) Set your email
git config --global user.email ___ # 👉 your email in "double quotes", e.g. "ada@example.com"
# 3) Confirm both values were saved
git config --global --listuser.name=Ada Lovelace
user.email=ada@example.com___ blanks with your own name and email (in double quotes), then run it. The last command should list both values.3️⃣ Git's Three Areas
Understanding Git's three areas is the key to mastering it. The Working Directory is your actual files on disk. The Staging Area (also called the index) is where you line up exactly which changes go into the next commit. The Repository is the permanent, saved history. The flow is always the same: edit → git add (stage) → git commit (save). Notice how git status below shows a file moving from "not staged" to "to be committed".
# Git's three areas: Working Directory -> Staging Area -> Repository.
# Edit two files, then move them through the areas one at a time.
# 1. Edit index.html and style.css, then see their state
git status
# 2. Stage ONLY index.html (move it to the staging area)
git add index.html
git status
# 3. Commit it (move the staged snapshot into the repository)
git commit -m "Update HTML"
# 4. Now stage and commit style.css
git add style.css
git commit -m "Update CSS"On branch main
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
modified: index.html
modified: style.css
no changes added to commit (use "git add" and/or "git commit -a")
On branch main
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
modified: index.html
Changes not staged for commit:
modified: style.css
[main 1a2b3c4] Update HTML
1 file changed, 2 insertions(+), 1 deletion(-)
[main 5d6e7f8] Update CSS
1 file changed, 3 insertions(+)4️⃣ Your First Repository
Use git init to turn a folder into a repository, git add to stage files, and git commit to save a snapshot. Lean on git status constantly — it tells you exactly what state every file is in. Here's the whole cycle, start to finish.
# Create a brand-new repository and make your first commit.
# 1. Make a project folder and initialise a repo inside it
mkdir my-project
cd my-project
git init
# 2. Create a file
echo "# My Project" > README.md
# 3. See the untracked file
git status
# 4. Stage it, then commit a snapshot
git add README.md
git commit -m "Initial commit"
# 5. View the history
git log --onelineInitialized empty Git repository in /home/you/my-project/.git/
On branch main
No commits yet
Untracked files:
(use "git add <file>..." to include in what will be committed)
README.md
nothing added to commit but untracked files present (use "git add" to track)
[main (root-commit) a1b2c3d] Initial commit
1 file changed, 1 insertion(+)
create mode 100644 README.md
a1b2c3d Initial commitYour turn to drive the whole cycle. Fill in the three blanks below, then run the commands in order — you'll go from an empty folder to a repository with one commit.
# 🎯 YOUR TURN — turn a folder into a repo and make its first commit.
# Fill in each ___ , then run the commands in order.
mkdir notes
cd notes
# 1) Create the repository in this folder
git ___ # 👉 the command that starts a new repo
echo "My first note" > note.txt
# 2) Stage note.txt so it's ready to commit
git add ___ # 👉 the filename you just created
# 3) Save the snapshot with a message
git commit -m ___ # 👉 a short message in "double quotes", e.g. "Initial commit"
git log --onelineInitialized empty Git repository in /home/you/notes/.git/
[main (root-commit) f0e1d2c] Initial commit
1 file changed, 1 insertion(+)
create mode 100644 note.txt
f0e1d2c Initial commit___ using the hints, then run the commands. The final git log --oneline should show your single commit.Common Errors (and the fix)
- "nothing to commit, working tree clean" when you expected a commit — you ran
git commitwithoutgit addfirst. A modified file is invisible to a commit until you stage it. Rungit add <file>, then commit. - "Author identity unknown … Please tell me who you are" — you have not set
user.name/user.emailyet. Fix it once withgit config --global user.name "Your Name"andgit config --global user.email "you@example.com", then commit again. - "fatal: not a git repository (or any of the parent directories): .git" — you're running Git in a folder that isn't a repo, or you committed into the wrong directory. Check where you are with
pwd,cdinto the right folder, and rungit initif it really is a new project.
Pro Tips
- 💡 Run
git statusafter every command while learning. It's the fastest way to build a mental model of what Git is doing. - 💡 Commit small and often. Each commit should be one logical change — easier to read, revert, and understand later.
- 💡 Write messages in the imperative: "Add login page", not "added stuff". It reads like an instruction the commit carries out.
📋 Quick Reference — Essential Git Commands
| Command | What It Does |
|---|---|
| git init | Turn the current folder into a new repository |
| git status | Show what's changed, staged, or untracked |
| git add <file> | Stage a file for the next commit |
| git commit -m "msg" | Save a snapshot of the staged changes |
| git log --oneline | View the commit history, one line each |
| git config --global user.name "..." | Set the name stamped on your commits |
| git config --global user.email "..." | Set the email stamped on your commits |
Frequently Asked Questions
Q: What is the difference between Git and GitHub?
Git is the version-control tool that runs on your computer and tracks your project's history. GitHub is a website that hosts Git repositories online so you can back them up and collaborate. You can use Git all day without ever touching GitHub.
Q: Why do I have to run git add before git commit?
Git separates choosing what to save (staging, done with git add) from actually saving it (committing). This lets you commit only some of your changed files at once, keeping each commit focused. A file you edited but did not git add is simply left out of the commit.
Q: Do I need an internet connection to use Git?
No. Git is distributed, so the full history lives on your machine. git init, git add, git commit, git log and git status all work completely offline. You only need a network for commands that talk to a remote, like git clone, git push and git pull.
Q: Do I have to set git config every time I make a repository?
No. Running git config with the --global flag sets your name and email once for your whole machine, so every repository uses them automatically. You only set it again if you want a different name or email for one specific project (use git config without --global inside that repo).
Mini-Challenge: Build a Recipes Repo
No commands are filled in this time — just a brief and an outline. Work through it in your own terminal, then check your result against the expected output in the comments. This is exactly the loop you'll run at the start of every real project.
# 🎯 MINI-CHALLENGE: Build a "recipes" repository from scratch.
# No commands are filled in — work from the steps below, then run them.
#
# 1. Make a folder called "recipes" and move into it.
# 2. Initialise a Git repository inside it.
# 3. Create a file: echo "# Recipes" > README.md
# 4. Check the status — README.md should show as "Untracked".
# 5. Stage README.md, then commit it with the message "Add README".
# 6. Run git log --oneline to confirm exactly ONE commit exists.
#
# ✅ Expected: 'git status' shows "nothing to commit, working tree clean"
# and 'git log --oneline' shows a single line ending in "Add README".
# your commands heregit log --oneline should show exactly one commit ending in "Add README".🎉 Lesson Complete!
- ✅ Version control records your project's history so you can review and undo changes
- ✅ Git is distributed — the full history lives on your machine and works offline
- ✅ Changes flow through three areas: Working Directory → Staging → Repository
- ✅ Set your identity once with
git config --global user.name/user.email - ✅
git init→ edit →git add→git commitcreates your first repo and snapshot - ✅ Next lesson: Git Basics — clone existing repos and master the daily add-commit loop
Sign up for free to track which lessons you've completed and get learning reminders.