Git Level 2 Test

Updated · 10 min read

A new driver who can steer around an empty car park still has to show they can drive in traffic, with other cars around them. This test does the same for Git: it checks whether you can work alongside other people. It covers branches and HEAD, merging and conflicts, remotes, pushing and pulling, pull requests and forks, stashing and tags. If you pass it, you are ready to rebase and rewrite history.

How the Test Works

  • What's in it: 20 multiple-choice questions, then 3 puzzles where you work out what Git prints at the end of a short terminal session.
  • Time: 30 minutes, without notes and without running Git.
  • Pass mark: 16 out of 23. The quiz marks the 20 questions for you; give yourself one point for each puzzle you get exactly right.
  • What it covers: the lessons from "Git Branch" to "Releases and Semantic Versioning".

Part 1: 20 Questions

Level 2 test: 20 questions

20 questions
1What happens on disk when you run git branch feature/books?
2Which command creates a branch and switches to it in one step?
3After git switch main, what does .git/HEAD contain?
4When can Git merge with a fast-forward?
5Why might a team use git merge --no-ff?
6In a conflicted file, which part is between <<<<<<< HEAD and =======?
7A merge has conflicts and you want to start over. Which command?
8What is origin/main?
9What does git fetch change in your repository?
10Your push is rejected because the remote has commits you don't have. What should you do?
11What does git push -u origin feature/books do besides pushing?
12Why is --force-with-lease safer than --force?
13You contribute to a project where you can't push. What is the usual flow?
14Which of these is true about pull requests?
15Which SSH key file do you upload to GitHub, GitLab or Bitbucket?
16What does git stash save by default?
17What is the difference between git stash pop and git stash apply?
18What is the difference between a lightweight tag and an annotated tag?
19Does git push send your tags?
20In semantic versioning, which version follows 2.4.1 after adding a new, backward-compatible feature?

Part 2: "What Does Git Print?" Puzzles

Work out what the last command of each session prints, on paper, before you open the solution. Each session starts in a new, empty temporary folder, with your name and email address set and main as the default branch.

Puzzle 1: A Merge Commit

Terminal
cd "$(mktemp -d)"
git init --quiet
echo 'Term fee: $12,000' > fees.txt
git add fees.txt
git commit --quiet -m "Add the term fee"
git switch --quiet -c feature/books
echo 'Books fee: $600' > books.txt
git add books.txt
git commit --quiet -m "Add the books fee"
git switch --quiet main
echo 'Exam fee: $800' > exam.txt
git add exam.txt
git commit --quiet -m "Add the exam fee"
git merge --quiet --no-edit feature/books
git log --graph --format=%s
Show solution
Terminal
cd "$(mktemp -d)"
git init --quiet
echo 'Term fee: $12,000' > fees.txt
git add fees.txt
git commit --quiet -m "Add the term fee"
git switch --quiet -c feature/books
echo 'Books fee: $600' > books.txt
git add books.txt
git commit --quiet -m "Add the books fee"
git switch --quiet main
echo 'Exam fee: $800' > exam.txt
git add exam.txt
git commit --quiet -m "Add the exam fee"
git merge --quiet --no-edit feature/books
git log --graph --format=%s
Output
*   Merge branch 'feature/books'
|\
| * Add the books fee
* | Add the exam fee
|/
* Add the term fee
Why this output?

Both branches had a new commit, so a fast-forward was impossible and Git made a merge commit with the default message "Merge branch 'feature/books'". The graph shows main's own commit on the left line and the branch's commit on the right, joining at the merge. Revise: Fast-Forward vs Merge Commit.

Puzzle 2: Two Stashes

Terminal
cd "$(mktemp -d)"
git init --quiet
echo 'Term fee: $12,000' > fees.txt
git add fees.txt
git commit --quiet -m "Add the term fee"
echo "Late fee idea" >> fees.txt
git stash push --quiet -m "late fee idea"
echo "Exam fee idea" >> fees.txt
git stash push --quiet -m "exam fee idea"
git stash list
Show solution
Terminal
cd "$(mktemp -d)"
git init --quiet
echo 'Term fee: $12,000' > fees.txt
git add fees.txt
git commit --quiet -m "Add the term fee"
echo "Late fee idea" >> fees.txt
git stash push --quiet -m "late fee idea"
echo "Exam fee idea" >> fees.txt
git stash push --quiet -m "exam fee idea"
git stash list
Output
stash@{0}: On main: exam fee idea
stash@{1}: On main: late fee idea
Why this output?

Stashes are a stack: the newest is always stash@{0}, and older ones move down one number. Each entry says which branch it was made on and its message. Revise: Git Stash.

Puzzle 3: Behind After a Fetch

Terminal
cd "$(mktemp -d)"
git init --quiet --bare server.git
git clone --quiet server.git navika 2>/dev/null
cd navika
echo 'Term fee: $12,000' > fees.txt
git add fees.txt
git commit --quiet -m "Add the term fee"
git push --quiet -u origin main
cd ..
git clone --quiet server.git advitha
cd advitha
echo 'Late fee: $250' >> fees.txt
git commit --quiet -am "Add the late fee"
git push --quiet
cd ../navika
git fetch --quiet
git status --short --branch
Show solution
Terminal
cd "$(mktemp -d)"
git init --quiet --bare server.git
git clone --quiet server.git navika 2>/dev/null
cd navika
echo 'Term fee: $12,000' > fees.txt
git add fees.txt
git commit --quiet -m "Add the term fee"
git push --quiet -u origin main
cd ..
git clone --quiet server.git advitha
cd advitha
echo 'Late fee: $250' >> fees.txt
git commit --quiet -am "Add the late fee"
git push --quiet
cd ../navika
git fetch --quiet
git status --short --branch
Output
## main...origin/main [behind 1]
Why this output?

git fetch updated origin/main with Advitha's commit but didn't touch Navika's main. So her branch is one commit behind its upstream, and git status --short --branch shows it in brackets. git pull (or git merge origin/main) would fast-forward it. Revise: Git Fetch.

What Your Score Means

Score (out of 23)What it meansWhat to do next
20 to 23You collaborate with confidenceMove on to Git Rebase
16 to 19A pass, with a few gapsRead the lessons linked from the questions you missed, then move on
Under 16Not yetReread the lessons behind your wrong answers, do Lab 2 on Git Labs, and take the test again

Was this tutorial helpful?