Introduction to Version Control
Reviewed & published by Brayan K
Git is a distributed version control system that tracks changes to your code over time, letting you save snapshots, work on features in separate branches, and undo mistakes.
Part of the free Git course at LearnCodingFast — hands-on lessons with worked examples and the output they print, plus practice exercises and a quick quiz.
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=short2️⃣ 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 "[email protected]"
# Recommended defaults
git config --global init.defaultBranch main
git config --global color.ui auto
# Check what you've configured
git config --listNow 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. "[email protected]"
# 3) Confirm both values were saved
git config --global --list3️⃣ 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"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 --onelineYour 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 --onelineCommon Errors (and the fix)
- "nothing to commit, working tree clean" when you expected a commit — you ran git commit without git add first. A modified file is invisible to a commit until you stage it. Run git add <file>, then commit.
- "Author identity unknown … Please tell me who you are" — you have not set user.name / user.email yet. Fix it once with git config --global user.name "Your Name" and git config --global user.email "[email protected]", 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, cd into the right folder, and run git init if it really is a new project.
Pro Tips
- 💡 Run git status after 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 |
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.
🎉 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 commit creates your first repo and snapshot
Practice quiz
What is Git?
- A cloud hosting website like GitHub
- A distributed version control system that tracks changes over time
- A programming language
- A code editor
Answer: A distributed version control system that tracks changes over time. Git is a distributed version control system; GitHub is a separate site that hosts Git repositories.
Which command turns the current folder into a new Git repository?
- git init
- git start
- git new
- git create
Answer: git init. git init creates a fresh .git directory, turning the folder into a repository.
In Git's three areas, where does git add move a changed file?
- Into the repository history
- Back to the working directory
- Into the staging area
- Onto a remote server
Answer: Into the staging area. git add moves changes from the working directory into the staging area, ready for the next commit.
Which command permanently saves the staged snapshot into the repository?
- git save
- git stage
- git push
- git commit
Answer: git commit. git commit records the staged snapshot into the repository history with a message.
What does git status show you?
- What is changed, staged, or untracked
- The full diff of every commit
- A list of remote branches
- Your global config values
Answer: What is changed, staged, or untracked. git status reports which files are modified, staged, or untracked right now.
Why must you run git add before git commit?
- git add uploads files to GitHub
- git add deletes old commits
- Staging lets you choose exactly which changes go into the commit
- It is only needed the first time
Answer: Staging lets you choose exactly which changes go into the commit. Staging separates choosing what to save from actually saving it, so a commit can include only some files.
What does the --global flag do in git config --global user.name?
- Sets the name only for the current commit
- Sets the name once for your whole machine
- Pushes your name to the remote
- Sets the name for everyone on the team
Answer: Sets the name once for your whole machine. --global stores the setting for your user account, so every repository on the machine uses it.
What is a commit?
- A remote server copy
- A branch label
- A list of ignored files
- A saved snapshot of your project at a point in time
Answer: A saved snapshot of your project at a point in time. Each commit is a permanent snapshot of your project that you can return to later.
Which command shows the commit history one line per commit?
- git log --oneline
- git history
- git show --short
- git commits
Answer: git log --oneline. git log --oneline prints a compact history with one short line per commit.
Which statement about Git being distributed is true?
- You always need internet to commit
- Only one person can hold the history
- The full project history lives on your own machine and works offline
- History is stored only on GitHub
Answer: The full project history lives on your own machine and works offline. Git is distributed: the complete history is on your computer, so init, add, commit, and log all work offline.
Continue this course
- Next: Git Basics: Clone, Add, Commit — The three core Git commands every developer uses every single day
- Quick reference: Git cheat sheet › Getting Started
Frequently asked questions
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.
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.
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.
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).