Why version control saves you
Have you ever had a folder full of files like essay.docx, essay-final.docx, essay-final-2.docx and essay-final-REALLY-final.docx? Then you already understand the problem that version control solves.
When you write code, you change things all the time. Sometimes a change works. Sometimes it breaks everything, and you'd give anything to go back to how it was an hour ago. In this lesson you'll learn what version control is and why every single developer uses it.
What version control is
Version control is a system that remembers every version of your project. Whenever you reach a point you're happy with, you save a snapshot. Later, you can look back at any snapshot, see exactly what changed between them and go back if you need to.
It's a bit like the save points in a video game. You play through a tricky part and save. If things go wrong later, you load the save instead of starting the whole game over.
With version control you can:
- Go back in time when something breaks
- See what changed, line by line, and when
- Try out ideas safely without risking the version that works
- Work together with other people on the same code without overwriting each other's work
Git
The version control system almost everyone uses today is called Git. It was created in 2005 by Linus Torvalds, the same person who created Linux, and it's now used by everyone from students to the biggest tech companies in the world.
Git runs on your own computer. It keeps track of the files in a project folder and stores all the snapshots in a hidden folder inside it. You don't need an internet connection or an account to use it.
A few words you'll hear all the time:
- A repository, or repo for short, is a project folder that Git is keeping track of
- A commit is a snapshot of your project at a certain moment, with a short message describing what changed
- The history is the list of all commits, from the very first one to the latest
What is a commit?
Select one answer
Git and GitHub are not the same thing
This confuses almost everyone at first, so let's clear it up right away.
Git is the tool on your computer that tracks changes and saves snapshots.
GitHub is a website where you can store copies of your Git repositories online. It's a bit like a cloud backup for your code, with lots of extra features for working with others. GitHub is owned by Microsoft, and there are similar sites like GitLab and Bitbucket that do the same job.
You can use Git without GitHub. But using both together gives you an online backup of your code, a way to share it with others and, as you'll see at the end of this course, a free way to publish your website.
Which statement is true?
Select one answer
Why learn it now?
You might wonder why we're learning Git before JavaScript. Two reasons.
First, you already have a website worth saving. Your HTML and CSS work deserves a proper history, and from now on every change you make is safely stored.
Second, by the end of this course your website will be live on the internet with a real address. That's a great feeling, and it's a lot more motivating to keep learning when other people can actually see what you're building.
Also, every developer job and every team project uses Git. Learning it early means it'll feel completely natural by the time you need it.
You changed your CSS and now the whole page looks broken. How does version control help?
Select one answer
Think about the last time you lost work or wished you could undo something that couldn't be undone. Maybe a document, a photo edit or a school project.
Now look at your my-website folder. Imagine changing something in your CSS tomorrow and breaking the layout. Could you get back to today's version right now? If not, that's exactly what the next two lessons fix.