Why version control
Last updated
Before Pila had a repository, Marco and Bea swapped code by email, and the folder filled with queue_rules_final.py, queue_rules_final_v2.py and queue_rules_REAL.py. Then a working version was overwritten and nobody could get it back. In this lesson you'll see what version control does: keep every saved version, say who changed what and why, and let a team work on the same files without overwriting each other.
By the end of this lesson you can
- Explain what version control keeps and what it makes possible
- Describe how version control lets a team work on the same files
- Tell centralised and distributed version control apart
queue_rules_REAL.py
In Pila's first week, before anyone set up a repository, the shared folder looked like this:
queue_rules.py
queue_rules_final.py
queue_rules_final_v2.py
queue_rules_REAL.py
queue_rules_REAL_bea.py
queue_rules_REAL (1).pyWhich one is current? Which has Bea's fix for the opening hours? What changed between final and final_v2, and why? Nobody knows without opening all six and comparing them by eye.
Version control solves this. A version control system keeps a project's files in a repository, with every saved version of every file, who saved it, when, and a message saying why. There's one queue_rules.py, and its whole history is a command away. Git is the system nearly every team uses today; lessons 5.3 to 5.5 use it.
A month, with and without
- Week 1 Marco emails queue_rules.py to Bea. She fixes the opening hours and emails it back as queue_rules_final.py.
- Week 1 Meanwhile Marco added the 60-number limit to his own copy. Now there are two versions, each with one change.
- Week 2 Bea copies her file over Marco’s to “combine” them. The 60-number limit is gone, and nobody notices.
- Week 3 At the centre, number 61 is given out. Which file is running? Three candidates; nobody is sure.
- Week 3 Marco rewrites the limit from memory. It’s slightly different, and nobody can say how.
Without version control: A working version was overwritten, nobody could say which file was running, and a fix had to be rebuilt from memory.
Switch to the other side to compare.
What a history gives you
A repository's history is more than a backup:
| You can… | Because… | At Pila |
|---|---|---|
| Undo | every committed version is kept | Go back to the queue rules that worked on Monday |
| See what changed | any two versions can be compared line by line | What exactly changed in the limit between week 1 and week 3? |
| See who and why | each change has an author, a date and a message | “Close at 17:00, not 16:30: Ate Cora’s rule (3.P)” |
| Work at the same time | changes to the same files are combined, not overwritten | Marco and Bea both change queue_rules.py on the same day |
| Try things safely | a branch is a separate line of work (lesson 5.4) | The priority lane is built on a branch until it’s ready |
| Know what’s running | each release is a named version (lesson 7.2) | The centre runs exactly the version tagged v1.0 |
Everything needed to build and run Pila belongs in the repository: code, tests, the README, the design documents, the deployment scripts. Passwords and other secrets don't (lesson 4.7); Simple Git's A secret got committed says what to do if one slips in.
Centralised and distributed
There are two ways to arrange it:
- Centralised (CVS, Subversion): one server holds the history. Everyone checks files out from it and commits back to it. If the server is down, nobody can commit or see the history.
- Distributed (Git, Mercurial): every developer's copy is a full repository, with the whole history. They commit on their own computer, even offline, and share commits with a common copy on a hosting site when ready.
Git, created by Linus Torvalds in 2005 for the Linux kernel, is distributed. Pila's team keeps a shared copy on a hosting site (lesson 5.5), but Marco can commit on the jeepney with no signal, and if the hosting site disappeared, every laptop would still have the whole history.
This course uses what a team needs day to day. Simple Git covers it all in depth, starting from Why version control, with Just enough terminal and Installing and setting up for running Git on your own computer.
Spot the trap: emailing code
A new volunteer, Jun, has a fix for the waiting-room screen. “I don’t really know Git. Can I just email you the file?”
What happens if…
Check what you learned
Sources
Every claim on this page comes from these sources: the standard, the founding text of a method, a study, or the official record of a project, from the body that publishes it. Industry reports are labelled as such.
- Pro Git, 1.1: About Version Control (Scott Chacon and Ben Straub): local, centralised and distributed version control
- Git documentation: gittutorial: Git’s own introduction: history, and working with others
- Martin Fowler: Continuous Integration: everything a build needs, kept in version control