π§ Lesson 1: Why Version Control? Installing & Configuring Git
You built a real website in the HTML & CSS course. Today you'll give it a superpower: a complete, rewindable history of every change you ever make. This first lesson explains what version control is and why every developer uses it, then gets Git installed and set up on your computer so you're ready to start saving snapshots in Lesson 2.
π― Learning Objectives
By the end of this lesson, you will be able to:
- Explain what version control is and name four problems it solves
- Describe the difference between Git (a tool on your computer) and GitHub (a website)
- Describe Git's three areas: the working folder, the staging area, and the repository of commits
- Install Git on Windows, macOS, or Linux and confirm it works with
git --version - Configure your name, email, default branch, and editor with
git config --global - Open VS Code's integrated terminal and run Git commands from it
Estimated Time: 40 minutes (about half of it hands-on)
Project: Install Git and configure it, ready to put your my-website folder under version control
In This Lesson
π© The final-v2-REALLY-final Problem
Be honest: have you ever had a folder that looked like this?
index.html
index-old.html
index-backup.html
index-final.html
index-final-v2.html
index-final-v2-REALLY-final.html
index-final-v2-REALLY-final-USE-THIS-ONE.html
Everybody does this at some point. You're about to try something risky, so you make a copy "just in case." A week later you have seven copies, you can't remember which one is live on Netlify, and you have no idea what's different between final-v2 and REALLY-final.
Now think about your my-website folder from the HTML & CSS course. What if you redesign the navigation, it breaks on phones, and you only notice three days later, after you've changed ten other things? Copying files by hand can't rescue you from that. Version control can.
π± A Note Before We Start
Git has a reputation for being scary. It isn't, once you know the handful of commands you'll learn today. You will type something wrong, see a confusing message, or end up somewhere unexpected. That's not failure: mistakes are how you learn Git. And the whole point of Git is that almost nothing is permanent, so you're safer experimenting than you've ever been.
πΎ What Version Control Does
Version control is a system that records snapshots of your project over time, so you can see what changed, when, and why, and go back to any earlier snapshot whenever you need to.
Two ways to picture it:
- Save points in a video game. Before the boss fight, you save. If it goes badly, you reload the save and try again. Git lets you make a save point of your website whenever you like, as many as you like.
- A lab notebook of snapshots. A scientist writes down every experiment: the date, what they changed, and what happened. Git keeps that notebook for you automatically, and every entry includes a complete photo of the whole project at that moment.
The problems it solves
| Problem | How version control fixes it |
|---|---|
A folder full of -final-v2 copies |
One folder, one set of files. The history lives inside Git, not in file names. |
| "It worked on Tuesday. What did I change?" | Undo across days, not just across the last few edits. Compare any two snapshots line by line. |
| Afraid to try a risky redesign | Safe experiments: try the idea on a separate line of work (a branch), and throw it away if it doesn't pan out. |
| Two people editing the same site | Collaboration: Git merges everyone's changes and tells you exactly where two edits clash. |
| Laptop dies, and the site goes with it | Backup: push your history to GitHub and it's safe off your machine, ready to download anywhere. |
Here's what a history of your site might look like by the end of today. Each dot is a snapshot, called a commit, with a short message describing what changed:
Every one of those dots is a complete snapshot you can look at or return to, even months later.
π§ Git vs GitHub
These two names get mixed up constantly, so let's settle it now:
| Git | GitHub | |
|---|---|---|
| What it is | A free program you install on your computer | A website (github.com) that hosts Git projects online |
| What it does | Records snapshots, shows history, undoes changes, manages branches | Stores a copy of your project online, adds sharing, pull requests, and collaboration tools |
| Needs the internet? | No. Works completely offline | Yes |
| When we use it | All day, starting now | This afternoon (Lessons 5 and 6) |
A handy comparison: Git is like your camera, which takes the photos. GitHub is like an online photo album where you upload them to keep them safe and share them. You can take plenty of photos without ever uploading any, and that's exactly what the whole morning looks like.
π‘ Other hosting sites exist
GitHub is the most popular place to host Git projects, but GitLab and Bitbucket do the same job. The Git skills you learn today work with all of them, because the tool on your computer is the same.
ποΈ The Mental Model: Three Areas
This is the most important idea of the whole day. Once it clicks, every Git command makes sense. Git thinks about your project in three places:
- Working folder: your
my-websitefolder, exactly as you see it in VS Code. This is where you edit files, the same as always. - Staging area: a "getting ready" area where you place the changes you want in your next snapshot. Think of it as arranging people before you take a group photo.
- Repository: the permanent collection of snapshots (commits). Git stores it in a hidden folder named
.gitinside your project.
(you edit files here)"] -->|"git add"| B["π Staging area
(changes picked for the next snapshot)"] B -->|"git commit"| C["π Repository
(saved snapshots = commits)"] style A fill:#fef3c7,stroke:#f59e0b,stroke-width:2px,color:#1e293b style B fill:#eff6ff,stroke:#3b82f6,stroke-width:2px,color:#1e293b style C fill:#ecfdf5,stroke:#22c55e,stroke-width:2px,color:#1e293b
So the rhythm of working with Git is:
- Edit your files as usual (in the working folder).
- Stage the changes you want to keep together with
git add. - Commit them as one snapshot, with a message, using
git commit.
π€ Why have a staging area at all?
Because it lets you choose. Suppose you fixed a typo on the About page and started a half-finished new color scheme in style.css. You can stage and commit just the typo fix, with a clear message, and leave the color work for later. Each snapshot then tells one clean story. You'll try this for real in Lesson 2.
β¨οΈ Opening VS Code's Terminal
Git is a command-line tool: you type short commands and it answers with text. You don't need a separate app for this. VS Code has a terminal built in, and it opens right in your project folder.
- Open VS Code.
- Open the terminal with Ctrl + ` (the backtick key, usually above Tab). On a Mac it's also Control + `. You can always use the menu instead: View β Terminal (or Terminal β New Terminal).
- A panel appears at the bottom with a blinking cursor. That's the prompt. Type a command, press Enter, and read the reply.
πͺ Windows: PowerShell or Git Bash?
On Windows, VS Code's terminal starts in PowerShell. After you install Git, you'll also be able to pick Git Bash from the β dropdown next to the + in the terminal panel. Either one works for everything in this class. Every command on these pages is written to work the same in PowerShell, Git Bash, and the macOS or Linux terminal.
π‘ Terminal tips that save time
- Press β to bring back the previous command, so you can fix a typo without retyping everything.
- Git commands are case-sensitive and need spaces in the right places:
git status, notGit Statusorgitstatus. - If a command seems stuck, press q (to leave a scrolling view) or Ctrl + C (to cancel).
π₯ Installing Git
First, check whether Git is already on your computer. Many Macs and Linux machines have it. In the VS Code terminal, type:
git --version
If you see something like this, Git is installed and you can skip ahead to Configuring Git:
git version 2.51.0
(Your number will differ. Anything 2.40 or newer is perfect for this class.) If you get an error such as "git is not recognized" or "command not found", follow the steps for your system below.
πͺ Windows: Git for Windows
- Go to git-scm.com/downloads, choose Windows, and download the 64-bit installer (it's named like
Git-2.xx.x-64-bit.exe). - Run it. The installer has a lot of screens. Accept the default on every screen except these two:
- "Choosing the default editor used by Git": open the dropdown and pick Use Visual Studio Code as Git's default editor. (The default is Vim, which is famously hard to exit.)
- "Adjusting the name of the initial branch in new repositories": choose Override the default branch name for new repositories and make sure the box says
main.
- Keep going with the defaults. You'll pass a screen about a credential helper with Git Credential Manager selected. Leave it that way: it's what will let you sign in to GitHub with your browser this afternoon.
- Click Install, then Finish.
- Close VS Code completely and reopen it, so its terminal picks up the newly installed Git. Then run
git --versionagain.
π macOS
- In the VS Code terminal (or the Terminal app), run
git --version. - If Git isn't installed yet, macOS pops up a dialog offering to install the command line developer tools. Click Install and wait a few minutes. These are Apple's Xcode Command Line Tools, and they include Git. (You do not need the full Xcode app.)
- When it finishes, run
git --versionagain.
Already use Homebrew? You can run brew install git instead to get the very latest version. Either way is fine for this class.
π§ Linux
Use your distribution's package manager, then check the version:
# Ubuntu, Debian, Linux Mint
sudo apt install git
# Fedora
sudo dnf install git
# Then confirm it worked
git --version
β οΈ "git is not recognized" even after installing?
Nine times out of ten, the terminal was opened before Git was installed, so it doesn't know Git exists yet. Close every VS Code window, open VS Code again, and open a fresh terminal. On Windows, if that still fails, restart the computer. If you're still stuck, flag down your instructor. This is a common hiccup, not a sign you did anything wrong.
βοΈ Configuring Git
Git stamps every commit with the author's name and email, so it needs to know who you are. You set this up once per computer, using git config --global. The word global means "for every project on this computer," so you won't have to do it again.
1. Your name
Use your real name (or whatever name you'd like to appear on your work). Keep the quotation marks:
git config --global user.name "Your Name"
2. Your email
git config --global user.email "you@example.com"
This afternoon you'll connect to GitHub. Using the same email you use (or will use) for your GitHub account means GitHub can link your commits to your profile.
π Prefer to keep your email private?
Commits you publish on GitHub show the email you set here. If you'd rather not share your real address, GitHub gives every account a private noreply address. After you create your account (Lesson 5), find it under Settings β Emails, where you can also turn on Keep my email addresses private. It looks like 12345678+yourname@users.noreply.github.com. You don't need to decide right now: you can re-run the user.email command at any time, and it applies to future commits.
3. The default branch name
Every new project starts with one line of history, called a branch. Today's standard name for it is main, which is also what GitHub uses. This setting makes sure your new projects use it too:
git config --global init.defaultBranch main
(If you chose the "Override" option in the Windows installer, this is already set. Running it again does no harm.)
4. Your editor
Occasionally Git needs you to type a longer message and opens a text editor for it. Let's make that editor VS Code:
git config --global core.editor "code --wait"
The --wait part tells Git to wait until you close that VS Code tab before carrying on.
β οΈ Mac users: is the code command available?
The editor setting only works if typing code in a terminal opens VS Code. On Windows, the VS Code installer sets this up (the "Add to PATH" box from the HTML & CSS course). On a Mac, open VS Code's Command Palette with Cmd + Shift + P, type shell command, and choose Shell Command: Install 'code' command in PATH. Test it by running code --version.
5. Check your settings
git config --global --list
You should see your four settings (possibly among a few others):
user.name=Your Name
user.email=you@example.com
init.defaultbranch=main
core.editor=code --wait
Don't worry that Git shows defaultbranch in lowercase. Git setting names aren't case-sensitive, so it's the same setting. If the list is long and ends with a : or (END), press q to get your prompt back.
β Made a typo?
Just run the same command again with the right value. Each git config --global command replaces the old value for that setting.
β Common Questions
Does installing Git upload my website anywhere?
No. Git works entirely on your own computer. Nothing goes online until you deliberately push to GitHub, which you'll do in Lesson 5.
Do I need a GitHub account yet?
Not this morning. You'll create a free one at the start of Lesson 5. If you already have one, great: use the same email in user.email.
Is Git only for programmers?
Git works best with plain-text files, which is exactly what HTML and CSS are. Writers, designers, and scientists use it too. It's less helpful for things like Word documents or Photoshop files, because it can't show line-by-line changes inside them.
VS Code already has a "Source Control" icon. Why learn commands?
You'll use that panel too, starting in Lesson 2. But the buttons are just running Git commands for you. Knowing the commands means you understand what the buttons do, you can follow any tutorial online, and you can read Git's messages when something unexpected happens.
Hands-on Exercise
ποΈ Exercise: Get Git Ready
Objective: Install Git, configure it, and prove it's working, so you're ready to put your website under version control in the next lesson.
Instructions:
- Open VS Code, then open the integrated terminal (Ctrl + `).
- Run
git --version. If Git is missing, install it for your system using the steps above, then restart VS Code and run it again. - Set your name with
git config --global user.name "...". - Set your email with
git config --global user.email "...". - Set the default branch with
git config --global init.defaultBranch main. - Set VS Code as Git's editor with
git config --global core.editor "code --wait". - Run
git config --global --listand check all four values. - Find your
my-websitefolder from the HTML & CSS course (or the starter site from your instructor) and open it in VS Code with File β Open Folderβ¦. Leave it open: it's your project for the rest of the day.
Deliverable: your git config --global --list output showing user.name, user.email, init.defaultbranch=main, and core.editor=code --wait, plus your site folder open in VS Code.
π‘ Hint
The two most common problems: (1) the terminal was opened before Git was installed, so close all VS Code windows and reopen; (2) a missing quotation mark, which leaves the terminal waiting with a >, >> (PowerShell), or quote> (Mac) prompt. Press Ctrl + C to cancel and try again with both quotes in place.
β Solution
Here's the complete sequence (with your own name and email):
git --version
git config --global user.name "Ada Lovelace"
git config --global user.email "ada@example.com"
git config --global init.defaultBranch main
git config --global core.editor "code --wait"
git config --global --list
And the check at the end should include:
user.name=Ada Lovelace
user.email=ada@example.com
init.defaultbranch=main
core.editor=code --wait
π Want to go further?
Test your editor setting: run git config --global --edit. VS Code should open a file named .gitconfig showing your settings, and the terminal waits. Look around (don't change anything), then close that tab. The terminal gets its prompt back. That's exactly how --wait works. Then try git help config to see Git's built-in manual (press q to leave it if it opens in the terminal).
π― Quick Quiz
Question 1: Which statement about Git and GitHub is true?
Question 2: What is the staging area for?
Question 3: Which command confirms that Git is installed and shows which version you have?
Question 4: Why do you set user.name and user.email?
Question 5: What does git config --global init.defaultBranch main do?
π Learning Journal
Take five minutes to add to your learning journal. Write down:
- Key concepts you learned
- What clicked β the idea or technique that made sense
- Questions or confusion, so you know what to revisit
- Ideas to try on your own pages
- How you feel about your progress
βοΈ This lesson's prompt: Think back to building your website in the HTML & CSS course. Describe one moment when you broke something, lost work, or were afraid to try a change. How would a history of snapshots have helped? Then explain the working folder, staging area, and repository in your own words, as if to a friend who has never heard of Git.
Summary
π Key Takeaways
- Version control records snapshots of your project so you can see, compare, and return to any earlier version
- It solves the final-v2 problem, lets you undo across days, makes experiments safe, and enables collaboration and backup
- Git is the tool on your computer; GitHub is a website that hosts Git projects
- Git's three areas: working folder β
git addβ staging area βgit commitβ repository git --versionchecks your install;git config --globalsets your name, email, default branch (main), and editor once per computer- On Windows, PowerShell and Git Bash both work for everything in this class
π Additional Resources
- Git β Downloads
- Pro Git book β What is Git? (free online)
- Pro Git book β First-Time Git Setup
- GitHub Docs β Setting your commit email address
π What's Next?
Git is installed and knows who you are. In the next lesson, you'll turn your my-website folder into a repository with git init, make your first commits, write good commit messages, and do the same thing with a few clicks in VS Code's Source Control panel.