Lesson 1
What version control is, and where Git and GitHub fit
What you'll learn: what version control is, why it beats saving copies of files, and how Git, GitHub and the command line fit together.
Meet Sam and the bakery website
Sam is a freelance web designer. Her current job is a small website for Rosa's Bakery: a home page, a menu page, a page with opening hours and a contact form. It is only a handful of files, but she has already run into the problem every designer knows. Her folder looks like this:
index.htmlindex-old.htmlindex-rosa-feedback.htmlindex-FINAL.htmlindex-FINAL-2.html
Which one is live? What changed between the second and third? When Rosa says "I preferred the header from two weeks ago", which file has it? Sam isn't sure. And soon her friend Leo, a developer, is going to help with the contact form, which means two people editing the same files.
This course follows Sam from that messy folder to a calm, shared project on GitHub.
What version control does
Version control is a system that records the changes to a set of files over time, so you can see what changed, when, why and by whom, and go back to any earlier version. Instead of you making copies with ever-longer names, the system keeps the history for you, and your folder holds just one current version of each file.
Think of save points in a video game. Before a tricky level, you save. If things go badly, you reload the save point and try again, without replaying the whole game. Version control gives your project save points, except that each one also carries a note saying what you did, and you can keep as many as you like.
Those save points are called commits. A commit is a snapshot of the whole project at a moment you choose, plus a short message, your name, and the date. Commits form a timeline you can read, compare and return to.
Version control also helps when several people work on the same files. It can combine their changes, and when two people change the same lines it flags the clash instead of silently keeping one and losing the other.
Git and GitHub are different things
People often say "Git" and "GitHub" as if they were the same. They are not.
| Git | GitHub | |
|---|---|---|
| What it is | A version control program | A website and service for hosting Git projects |
| Where it runs | On your own computer | On the internet |
| Works offline? | Yes, completely | No |
| Made by | Linus Torvalds, in 2005, for Linux development; now open source and maintained by a community | A company, owned by Microsoft since 2018 |
| Alternatives | Mercurial, Subversion (both much less common today) | GitLab, Bitbucket, and self-hosted servers |
Git does the actual version control: it records commits, manages history and combines changes. GitHub stores a copy of a Git project online so others can get it, and adds collaboration tools such as pull requests, code review and issue tracking. You can use Git without GitHub for years; you cannot meaningfully use GitHub without Git. Git is by far the most widely used version control system today, which is why this course is about it.
Sam will spend the first two-thirds of this course using Git alone on her laptop. GitHub comes in when Leo joins.
Git is distributed
Older systems kept the history on one central server, and you needed to be connected to save a version. Git is distributed: every copy of a project, on every computer, holds the full history. Sam can commit on a train with no signal, look back through months of history, and only connect to share her work. If GitHub disappeared tomorrow, every copy on every laptop would still hold the whole project.
Installing and introducing yourself
Git is a command-line program, and this course uses the commands directly, because they work the same everywhere and they are what every guide and error message refers to. Graphical tools such as GitHub Desktop, and the Git features built into editors like VS Code, run the same commands behind their buttons, so what you learn here carries straight over.
To get set up:
- Install Git. On Windows, use the official Git for Windows installer, which includes a terminal called Git Bash. On a Mac, Git is offered when you first run
gitin Terminal (it comes with Apple's command line tools), or you can install it with Homebrew. On Linux, use your package manager, for examplesudo apt install giton Ubuntu. - Check it worked by opening a terminal and running
git --version. Any recent version is fine for this course. - Tell Git who you are, since every commit records it. Sam runs these two commands, once per computer:
git config --global user.name "Sam Rivera"
git config --global user.email "sam@example.com"
The --global part means the setting applies to every project on this computer. Use the email you plan to use on GitHub, so your commits are linked to your account there.
One more setting is worth making now. Every project has a default branch (you will meet branches properly later). For years Git called it master; GitHub, GitLab and Bitbucket now name it main for new repositories, and many guides follow them. Depending on your Git version and settings, a new project may use either name. To make Git use main, which this course does, run:
git config --global init.defaultBranch main
If you join a project that uses master, nothing in this course changes except the name.
Recap
- Version control records a project's history as a series of snapshots called commits, each with a message, an author and a date, like save points in a video game.
- It replaces copies with names like
index-FINAL-2.html, and helps several people change the same files safely. - Git is the version control program on your computer; GitHub is an online service that hosts Git projects and adds collaboration tools.
- Git is distributed: every copy holds the full history and works offline.
- Set your name and email with
git config --globalbefore your first commit; the default branch may be calledmainormaster.