On this concept: Formula

Not sure which lesson to do first? Find your level and get a plan →

CS Thinking · Software Design & Development · Grade 9-12

Version Control

Version Control is a system (Git being the most common) that records changes to files over time using commits (snapshots), branches (parallel lines of work), and merges (combining changes), so you can revert to earlier versions, compare changes, and collaborate without overwriting each other.

c0→c1→⋯→cn

Quick Answer

Version Control is a system (Git being the most common) that records changes to files over time using commits (snapshots), branches (parallel lines of work), and merges (combining changes), so you can revert to earlier versions, compare changes, and collaborate without overwriting each other. Use it on any project that changes over time or has more than one author: commit after each working step with a message saying what changed and why, branch to try a feature without risking the working version, and merge when it is ready.

Why This Matters

With version control a bad change is never permanent: you can see the exact lines that changed between Tuesday's working version and Wednesday's broken one, and undo just that commit. Two people can edit the same project at once and merge, instead of emailing 'final_v3_REAL' files and overwriting each other. Without it, a deleted function or a bad edit can mean hours of rebuilding from memory.

Intuitive Explanation

Picture a project's history as a chain of snapshots. Commit c1: 'Add start screen'. Commit c2: 'Add score counter'. Commit c3: 'Fix score resetting to 0 on level 2'. Each commit records what every tracked file looked like at that moment, who made it, and a message saying why. Because every snapshot is kept, you can compare any two (c1 against c3 shows every line added since) or return to any one of them.

Branches let the chain split. On Monday Priya starts a branch called sound-effects from c3, while Tom stays on main and commits c4: 'Faster enemies'. Their work cannot interfere. When Priya's sounds work, she merges her branch into main and Git combines both sets of changes. If they both edited the same line of the same file, Git cannot know which version should win, so it stops with a merge conflict for a person to settle.

Saving a file is not committing. Pressing save overwrites the file on disk with its newest version, and the old version is gone. A commit is a deliberate, labelled snapshot added to the history. Cloud backups and a document's version history also keep old copies, but they do not let two people work on separate branches and then merge their changes, which is what software teams need.

Think of it like this. A commit is a video-game save point that comes with a note saying why you saved, and a branch is a copy of your save file for trying a risky route while the original stays safe. The comparison breaks at merging: a game cannot combine two save files, but Git can join two branches' changes into one.

Core idea. Version control enables collaboration, provides a complete history of changes, and makes it safe to experiment.


When to Use

Version control applies when a task mentions commits, branches, merges or reverting to an earlier state, or describes a team editing the same files, a change that broke something that worked yesterday, or the need to find who changed a line and why. If the question is about why the code needed changing at all, that is code maintenance; if it is about checking that a function still works after a change, use Unit Testing.

Tip. Ask: Does the task need a saved history of a project's changes, to go back, compare versions or combine people's work?

How to Recognize It

Look at what people need to do with earlier versions of the files and with each other's changes.

  1. Does someone need to get back an earlier working version after a change broke things?

    Yes means version control: go back to, or revert to, the last good commit. A single backup copy gives back only one moment, not every step in between.

  2. Are two or more people changing the same project at the same time?

    Yes means branches and merges let each person work separately and then combine the changes. Emailing files around overwrites someone's work sooner or later.

  3. Does the question ask who changed a line, when and why?

    Yes means read the commit history, because each commit records the author, the time and a message. An explanation of how the current code works belongs in Documentation.

  4. Is the question about making the change itself, such as fixing a bug or adding a feature?

    Yes means it is Code Maintenance or development; version control only records the change and lets you share or undo it.

Version Control vs Backup vs Code Maintenance vs Documentation

Version control keeps copies, supports maintenance and stores messages about changes, so it is confused with all three. Ask whether you need the full history of changes, one spare copy, the work of changing code, or an explanation of it.

Version Control

Meaning
Version control records each change to a project as a commit, building a history you can compare, branch, merge or undo.
Key test
A history of many versions, each with an author and a message.
Example
git log lists 40 commits, git diff compares any two of them, and git revert undoes one.

Backup

Meaning
A backup is a spare copy of files kept somewhere safe in case the originals are lost or damaged.
Key test
One saved moment, with no record of what changed or why.
Example
Copying the project to a cloud drive every night protects it if the laptop is stolen.

Code Maintenance

Meaning
Code maintenance is the work of fixing and improving software after release, which version control keeps track of.
Key test
The changes being made, not the record of them.
Example
Fixing a crash on older phones is maintenance; committing the fix records it.

Documentation

Meaning
Documentation explains how the current software works and how to use it, for the people reading it now.
Key test
Explains the present code, while commit messages explain its history.
Example
A README says how to run the game; a commit message says 'Fix menu crash on resize'.

Formula & Notation

c0→c1→⋯→cn
A version control system maintains a directed acyclic graph (DAG) of commits, where each commit ci records a snapshot of the project state and a pointer to its parent commit(s). Branching creates divergent paths; merging reconnects them.

Worked Examples

Example 1 — Find and undo the commit that broke scoring

Easy

A game's history on main is: c1 'Add player movement', c2 'Add coins', c3 'Change coin value from 10 to 1', c4 'Add pause menu'. Each coin should be worth 10 points, but at c4 each coin gives 1. Using the history, find the commit to undo and show the result.
Show the steps and the answer
  1. Read the commit messages for anything about scoring: c3 changed the coin value from 10 to 1.

    Clear messages let you find a behaviour change without opening every file.

  2. Confirm with a diff of c2 against c3: the line coin_value = 10 became coin_value = 1.

    The diff shows exactly which lines changed, so the bug came from c3 and not from the pause menu in c4.

  3. Revert c3: Git adds a new commit, c5, that changes coin_value = 1 back to coin_value = 10.

    A revert adds an undo commit instead of deleting history, so c4's pause menu stays and the record shows what happened.

  4. Play and collect 3 coins: the score is 30.

    3 × 10 = 30 confirms the intended value is back.

Answer: Revert c3. The new commit c5 restores coin_value = 10, the pause menu from c4 stays, and 3 coins score 30.

Takeaway: Small commits with clear messages turn 'what broke?' into reading the history and undoing one commit.

Example 2 — When Git cannot merge on its own

Standard

Lena and Omar both branch from main, where line 12 of game.py is speed = 5. Lena changes line 12 to speed = 7, and her branch is merged into main first. What happens when Omar merges his branch if (a) he changed only line 30, the background colour, or (b) he also changed line 12 to speed = 6?
Show the steps and the answer
  1. Case (a): Lena changed line 12 and Omar changed line 30, starting from the same version.

    Changes to different parts of a file can be combined, so Git merges automatically: main gets speed = 7 and Omar's new colour.

  2. Case (b): both branches changed line 12 away from speed = 5, one to 7 and one to 6.

    Git has no way to know which value is right, so it stops and marks line 12 as a conflict, showing both versions.

  3. Settle case (b): the team picks a value, say speed = 6, edits line 12 to it, and commits the merge.

    A conflict is a question for people, not a crash; the merge commit records their decision.

Answer: (a) Git merges automatically: speed = 7 plus Omar's colour. (b) Git reports a merge conflict on line 12, which a person resolves by choosing a value and committing.

Takeaway: Git combines edits to different lines by itself; two edits to the same line need a human decision.

Example 3 — Find the mistake: one giant commit

Application

Sam works on a weather app for a week and makes one commit: 'fixed stuff'. It contains a new 5-day forecast, a switch from Celsius to Fahrenheit everywhere, and a fix for a crash when the city name is blank. Users complain about Fahrenheit. Find the mistake and show how the history should have looked.
Show the steps and the answer
  1. Try to undo only the Fahrenheit change.

    With one commit it is impossible: reverting it also removes the forecast and brings back the blank-city crash.

  2. Read the message 'fixed stuff'.

    It names nothing, so a teammate scanning the history cannot even tell that the units changed.

  3. Split the work into three commits: 'Fix crash when city name is blank', 'Add 5-day forecast', 'Switch temperatures from Celsius to Fahrenheit'.

    Each commit holds one logical change with a message naming it, so any one can be reviewed or reverted alone.

  4. Revert only the third commit.

    The forecast and the crash fix stay, and Celsius comes back.

Answer: The mistake is one large commit mixing three unrelated changes under a vague message. With three focused commits, reverting 'Switch temperatures from Celsius to Fahrenheit' alone answers the complaint.

Takeaway: One logical change per commit, with a message saying what and why, keeps every change separately undoable.

Where You'll See It

  • Group essay in Google Docs vs. emailing files

    Version control is like Google Docs' version history but for code: instead of passing 'essay_final_v3_REAL.doc' around by email and overwriting each other, everyone edits a shared history that records who changed what and when.

  • A video game's save slots

    A commit is like a save point; if a new change breaks your game, you can roll back to an earlier 'save' (commit) instead of losing everything.

  • Two teammates editing the same file

    Branches let two students work on different features at once on the same project, then merge their changes together, instead of one person having to wait for the other to finish.

Common Mistakes

  1. The slip: A commit message can be anything, like 'fixed stuff' or 'asdf'.

    Why it's tempting: The code change is what matters and the message feels like a throwaway label.

    Instead: A good commit message states what changed and why, so that you (or a teammate) can later understand a change without re-reading every line of the diff.

  2. The slip: You can start working anytime without syncing, and Git will just sort it out.

    Why it's tempting: Git does merge automatically a lot of the time, so it seems safe to skip pulling.

    Instead: Pull the latest changes before starting work; editing a stale copy invites merge conflicts that pulling first would have avoided.

  3. The slip: Saving a file is the same as committing it.

    Why it's tempting: Both feel like 'storing your work,' and in many editors saving is the action you do most.

    Instead: Saving writes to disk only; committing records a snapshot in the project's tracked history that you can later inspect, compare, or revert to.


Mini Practice

Try these on your own. Tap Reveal when you want to check.

  1. main has commits c0, c1, c2, c3. You create branch feature at c2 and make 2 commits on it. Then main gets one new commit, c4. Before merging, how many commits does main have, and how many are only on feature?

    Hint: Commits made on feature after branching are not on main.

  2. Write a clear commit message for a change that fixes the quiz timer stopping at 59 seconds instead of 60.

    Hint: Say what changed and why in one short line.

  3. Ana and Ben both change line 12 of score.py from points = 10: Ana to points = 15 and Ben to points = 20. Ana merges first. What happens when Ben merges, and what must he do?

    Hint: Can the system decide on its own which value to keep?

  4. A bug appeared somewhere in the last 16 commits. Using binary search over the commits, as git bisect does, at most how many commits must you test?

    Hint: Each test halves the number of suspect commits.

  5. Situation A: a release broke the build, and the team wants yesterday's working state back without losing new feature work. Situation B: an engineer rewrites a slow function to make it faster. Which is mainly version control?

    Hint: Which one is about recovering or combining saved versions?

  6. A student says: 'I'll bundle the bug fix, the new feature and the formatting cleanup into one big commit, so I only write one message.' What should they do instead?

    Hint: Think about reviewing or undoing just one of those changes later.

Want the full set?

50 practice questions for this concept — free to try, every one with a complete worked solution showing the why, not just the answer.

Frequently Asked Questions

What is a merge conflict, and how do I fix one?

A merge conflict happens when two branches change the same lines of a file in different ways, so Git cannot tell which version to keep. Git stops and marks the clash inside the file, showing both versions between rows of marker symbols. You decide what the final lines should be, delete the markers, test that the program still works, and commit. Conflicts are normal, and merging small changes often keeps them small.

Is Git the same as GitHub?

No. Git is the version control program that runs on your own computer and keeps a project's history in a hidden .git folder; it works with no internet at all. GitHub is a website that stores copies of Git projects online so teams can share them, review each other's changes and report problems. GitLab and Bitbucket offer the same kind of service, and all of them use Git underneath.

How often should I commit?

Whenever you reach a small step that works, such as a finished function or a fixed bug, which for many people means several times an hour while coding. Small commits are easy to describe in one line, easy to review and easy to undo without losing other work. A single commit at the end of the day called 'lots of changes' is almost as hard to use as no history at all.

Can version control be used for things other than code?

Yes. Anything stored as text works well: writers keep books in Git, scientists track data and analysis scripts, and some governments have published their laws that way so every change to the wording is recorded. Images and videos can be stored too, but Git cannot show what changed inside them, so large media projects often add tools such as Git LFS.

Learning Path

← Before

Code Maintenance
Version Control

You are here

Next →

Nothing after this yet
You should know Code Maintenance, since version control is the record of every maintenance change. It adds commits, branches and merges, so a team can compare, undo and combine changes safely. With it you can run group software projects, review a teammate's branch before it joins main, track down the commit that introduced a bug, and have unit tests run automatically on every commit.

See Also