Saving the Story of Your Code
A first look at version control and Git
- say what version control is, in simple words,
- explain what a commit and a project's history are,
- describe the idea of a branch and why it keeps work safe,
- say what Git is.
1. What is version control?
Version control is a way of saving the history of your work so you never lose it. Every time you finish a little piece, you save a snapshot. Later you can look back at every snapshot, or even jump back to an older one if you make a mistake.
Think of writing a story. You might write draft 1, then draft 2, then draft 3. What if draft 3 is worse and you want draft 2 back? If you kept every draft, that is easy. Version control keeps every draft of your code for you, automatically and neatly.
Programmers use it because code changes a lot. A working program can break with one small change. Version control lets you undo that change and get back the working version in seconds.
2. Commits: named snapshots
A commit is one saved snapshot of your project. It is like pressing "save" in a video game, but with a twist: you also write a short message that says what you changed. That way the history is easy to read later.
| What you did | A good commit message |
|---|---|
| Added a jumping cat | "Add a cat that jumps when you press space" |
| Changed the colours | "Make the background blue" |
| Fixed a bug | "Fix the score that counted twice" |
A commit remembers three things: what changed, who saved it, and when. So the history is like a diary of the project.