Git Level 3 Test
A cook who can follow a recipe is useful. A cook who can rescue a dish that went wrong, and explain what went wrong, runs the kitchen. This test checks the rescue skills of Git: rewriting and cleaning up history, moving commits between branches, recovering lost work, hunting down the commit that broke something, and working in a team's workflow. If you pass it, you are ready for the advanced level.
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 Rebase" to "Code Review and Pull Request Etiquette".
Part 1: 20 Questions
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 Straight Line After Rebase
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 switch --quiet feature/books
git rebase --quiet main
git log --graph --format=%sShow solution
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 switch --quiet feature/books
git rebase --quiet main
git log --graph --format=%s* Add the books fee
* Add the exam fee
* Add the term feeWhy this output?
The rebase replayed "Add the books fee" on top of main's newest commit, so the branch history is one straight line, with no merge commit. Compare this with the merge puzzle in the Level 2 test, which made the same changes with a fork and a merge. Revise: Git Rebase.
Puzzle 2: Autosquash
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: $25' >> fees.txt
git commit --quiet -am "Add the late fee"
echo 'Exam fee: $800' > exam.txt
git add exam.txt
git commit --quiet -m "Add the exam fee"
sed -i.bak 's/\$25$/$250/' fees.txt && rm fees.txt.bak
git commit --quiet -a --fixup=HEAD~1
GIT_SEQUENCE_EDITOR=true git rebase --quiet -i --autosquash HEAD~3
git log --format=%sShow solution
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: $25' >> fees.txt
git commit --quiet -am "Add the late fee"
echo 'Exam fee: $800' > exam.txt
git add exam.txt
git commit --quiet -m "Add the exam fee"
sed -i.bak 's/\$25$/$250/' fees.txt && rm fees.txt.bak
git commit --quiet -a --fixup=HEAD~1
GIT_SEQUENCE_EDITOR=true git rebase --quiet -i --autosquash HEAD~3
git log --format=%sAdd the exam fee
Add the late fee
Add the term feeWhy this output?
--fixup=HEAD~1 created a commit named "fixup! Add the late fee". --autosquash moved it right after "Add the late fee" in the to-do list and marked it fixup, and GIT_SEQUENCE_EDITOR=true accepted the list without opening an editor. The fix was folded in, so the fixup commit disappeared and the late fee commit now contains $250. Revise: Fixup Commits and Autosquash.
Puzzle 3: What the Reflog Remembers
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: $250' >> fees.txt
git commit --quiet -am "Add the late fee"
git reset --quiet --hard HEAD~1
git reflog --format=%gsShow solution
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: $250' >> fees.txt
git commit --quiet -am "Add the late fee"
git reset --quiet --hard HEAD~1
git reflog --format=%gsreset: moving to HEAD~1
commit: Add the late fee
commit (initial): Add the term feeWhy this output?
%gs prints each reflog entry's description, newest first: the reset, the commit it undid, and the first commit. The "lost" commit is still listed, so git reset --hard HEAD@{1} would bring it back. Revise: Git Reflog.
What Your Score Means
| Score (out of 23) | What it means | What to do next |
|---|---|---|
| 20 to 23 | You can clean up and rescue any history | Move on to Git Internals Overview |
| 16 to 19 | A pass, with a few gaps | Read the lessons linked from the questions you missed, then move on |
| Under 16 | Not yet | Reread the lessons behind your wrong answers, do Lab 3 and Lab 7 on Git Labs, and take the test again |
Was this tutorial helpful?