Version Control Examples in CS Thinking

Start with the recap, study the fully worked examples, then use the practice problems to check your understanding of Version Control.

This page combines explanation, solved examples, and follow-up practice so you can move from recognition to confident problem-solving in CS Thinking.

Concept Recap

A system that records changes to files over time so you can recall specific versions, compare changes, and collaborate without overwriting each other's work. Git is the most widely used version control system, using concepts like commits (snapshots), branches (parallel lines of development), and merges (combining changes).

Version control is an unlimited undo button for your entire project — plus the ability for multiple people to work on the same files simultaneously.

Read the full concept explanation →

How to Use These Examples

  • Read the first worked example with the solution open so the structure is clear.
  • Try the practice problems before revealing each solution.
  • Use the related concepts and background knowledge badges if you feel stuck.

What to Focus On

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

Common stuck point: A commit is a snapshot of your project at a point in time, not a copy of the whole project. Git stores differences, not duplicates.

Sense of Study hint: When learning version control, start with three basic operations: commit (save a snapshot of your changes with a message), branch (create a parallel copy to experiment on), and merge (combine your changes back into the main branch). Practice with small projects before using it on team projects.

Worked Examples

Example 1

easy
What is version control and why is it important? Describe what happens without it.

Answer

Version control tracks all changes to files with full history. Without it, managing file versions becomes chaotic and error-prone.

First step

1
Step 1: Version control is a system that records changes to files over time, allowing you to recall specific versions later.

Full solution

  1. 2
    Step 2: Without it: developers save files as 'project_v1', 'project_v2', 'project_final', 'project_FINAL_v2' — leading to confusion about which is current.
  2. 3
    Step 3: With version control (e.g., Git), there is one file with a complete history of changes. You can see who changed what, when, and why — and undo mistakes.
Version control is an essential tool in modern software development. It enables collaboration, provides a safety net for mistakes, and maintains a complete audit trail of all changes.

Example 2

medium
Explain these Git operations and their purpose: commit, branch, merge. How do they support team collaboration?

Practice Problems

Try these problems on your own first, then open the solution to compare your method.

Example 1

medium
Two developers both edit the same line of the same file on different branches. What happens when they try to merge? How should this be resolved?

Example 2

hard
Explain how version control supports the maintenance stage of the SDLC. Describe a scenario where the ability to revert to a previous version saves a project.

Example 3

easy
In Git, what is the term for a single saved snapshot of your project at a point in time?

Example 4

easy
What is the term for a parallel line of development that lets you work without affecting the main code?

Example 5

easy
What operation combines the changes from one branch into another?

Example 6

easy
Two branches edited the SAME line of the same file differently. What does Git report when you merge them?

Example 7

easy
Which is a better commit message? A) 'fixed stuff' B) 'Fix off-by-one in pagination total count'

Example 8

easy
Before starting new work on a shared branch, what should you do first to reduce conflicts?

Example 9

easy
True or false: version control lets multiple people work on the same files at the same time.

Example 10

easy
What is the term for undoing a commit by creating a new commit that reverses its changes?

Example 11

medium
A feature branch was created from main at commit c3c_3. Main then advanced to c5c_5, and the feature branch added ca,cbc_a, c_b. When you merge feature into main, how many parent commits does the resulting merge commit have?

Example 12

medium
Main has commits A-B-C. A branch starts at B and adds X. No further commits hit main. When you merge the branch into main, what kind of merge can Git perform?

Example 13

medium
A teammate force-pushes to rewrite the shared main branch's history that you already pulled. What is the main risk this creates for the team?

Example 14

medium
You commit a file with a password by mistake and then push. Which statement is correct?

Example 15

medium
Order these into the standard collaborative workflow: (1) commit, (2) pull latest, (3) push, (4) make changes. Give the sequence.

Example 16

medium
A single commit changes the login bug fix, renames 20 unrelated files, and adds a new feature. Why is this commit problematic?

Example 17

medium
After an automatic merge fails, Git inserts markers in the file. After the line beginning with '<<<<<<<', whose changes appear first?

Example 18

medium
You want to temporarily set aside uncommitted changes to switch branches, then restore them later. Which Git feature does this?

Example 19

medium
In a repository, what file is conventionally used to tell Git which files to NOT track (e.g., build outputs, secrets)?

Example 20

challenge
A branch was created from main at commit c3c_3 (the common ancestor). The branch added 3 commits and main added 2 commits, none touching the same files. Using a three-way merge, how many commits are processed to build the merge result, and how many parents does the merge commit have?

Example 21

challenge
Team policy: never rewrite shared history. A bad change is on main 5 commits back, and 4 newer commits depend on unrelated files. Which command safely removes ONLY the bad change without rewriting the 4 newer commits' history?

Example 22

challenge
Three developers branch from the same commit and each edit DIFFERENT lines of the same file, then merge sequentially into main. How many merge conflicts occur, and why?

Example 23

easy
Which Git command uploads your local commits to a remote repository?

Example 24

easy
Which Git command downloads the latest commits from the remote and merges them?

Example 25

easy
Which Git command creates a new branch named 'feature'?

Example 26

easy
A repository's main long-lived branch is typically called what?

Example 27

medium
You ran git commit\text{git commit} but forgot to add a file. Which command lets you include the file in the SAME commit?

Example 28

medium
What is the difference between git fetch\text{git fetch} and git pull\text{git pull}?

Example 29

medium
A feature branch has 5 commits. You want a single tidy commit on main. Which workflow achieves this?

Example 30

medium
Two engineers edit different lines of the same file in separate branches. They merge sequentially into main. How many conflicts arise?

Example 31

medium
What file lists patterns of files Git should NOT track?

Example 32

medium
Order these Git operations into a standard daily workflow: (a) push, (b) commit, (c) pull, (d) edit files.

Example 33

medium
You committed a large binary by accident. It is too big for the remote and rejected. Which command UNDOES the commit while keeping your file changes for re-staging?

Example 34

medium
What is a 'pull request' (or merge request)?

Example 35

medium
You committed a secret API key 10 commits ago. You ran git rm\text{git rm} and committed. Is the secret safe now?

Example 36

medium
What does HEAD\text{HEAD} refer to in Git?

Example 37

medium
What is the term for a snapshot label (e.g., 'v1.2.0') attached to a specific commit?

Example 38

medium
Which command shows the change history of the current branch?

Example 39

medium
Which command shows the line-by-line difference between your working directory and the last commit?

Example 40

hard
A merge commit has 2 parents. A fast-forward merge produces how many new commits and how many parents?

Example 41

hard
What is the difference between rebase\text{rebase} and merge\text{merge}?

Example 42

hard
You ran git reset –hard HEAD1\text{git reset --hard HEAD}^{\sim}1 and lost a commit. Is the commit recoverable, and how?

Example 43

hard
Three feature branches each made 2 commits from main. They all merge sequentially. Main was at c3c_3; now it has how many MORE commits at minimum (assuming no fast-forward)?

Example 44

challenge
Given the commit chain c0c1cnc_0 \to c_1 \to \cdots \to c_n, a bug was introduced between c0c_0 and cnc_n. Which Git command finds the offending commit in O(logn)O(\log n) steps via binary search?

Example 45

challenge
You force-pushed over a shared branch with 4 lost commits. Three teammates already pulled the previous version. What is the safest recovery plan?

Background Knowledge

These ideas may be useful before you work through the harder examples.

code maintenance