Git Level 4 Test
A mechanic who has only driven cars can tell you when something sounds wrong. A mechanic who has taken an engine apart can tell you why, and fix it. This test is for the engine: how Git stores objects and references, how it packs them, how attributes, hooks and settings change its behavior, how it copes with huge repositories and several repositories at once, how it keeps history trustworthy, and how it merges. It is the hardest of the level tests.
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 Internals Overview" to "How Git Merges".
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: Four Object Types
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 tag -a v1.0 -m "Release 1.0"
for name in HEAD "HEAD^{tree}" HEAD:fees.txt v1.0; do git cat-file -t "$name"; doneShow 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 tag -a v1.0 -m "Release 1.0"
for name in HEAD "HEAD^{tree}" HEAD:fees.txt v1.0; do git cat-file -t "$name"; donecommit
tree
blob
tagWhy this output?
HEAD names a commit, HEAD^{tree} its top-level tree, HEAD:fees.txt the blob of that file in that commit, and v1.0 an annotated tag, which is an object of its own (a lightweight tag would have printed commit). Revise: Git Objects: Blob, Tree, Commit and Tag.
Puzzle 2: Our Side Wins the Conflict
cd "$(mktemp -d)"
git init --quiet
printf "%s\n" "Term fee: 12000" "Exam fee: 800" "Late fee: 250" > fees.txt
git add fees.txt
git commit --quiet -m "Add the fees"
git switch --quiet -c advitha
printf "%s\n" "Term fee: 13000" "Exam fee: 800" "Late fee: 275" > fees.txt
git commit --quiet -am "Raise the term and late fees"
git switch --quiet main
printf "%s\n" "Term fee: 12000" "Exam fee: 800" "Late fee: 300" > fees.txt
git commit --quiet -am "Raise the late fee"
git merge --quiet -X ours --no-edit advitha
cat fees.txtShow solution
cd "$(mktemp -d)"
git init --quiet
printf "%s\n" "Term fee: 12000" "Exam fee: 800" "Late fee: 250" > fees.txt
git add fees.txt
git commit --quiet -m "Add the fees"
git switch --quiet -c advitha
printf "%s\n" "Term fee: 13000" "Exam fee: 800" "Late fee: 275" > fees.txt
git commit --quiet -am "Raise the term and late fees"
git switch --quiet main
printf "%s\n" "Term fee: 12000" "Exam fee: 800" "Late fee: 300" > fees.txt
git commit --quiet -am "Raise the late fee"
git merge --quiet -X ours --no-edit advitha
cat fees.txtAuto-merging fees.txt
Term fee: 13000
Exam fee: 800
Late fee: 300Why this output?
The first line comes from git merge, which still says which file it merged even with --quiet. Only the late fee changed on both sides, so only it conflicted, and -X ours settled it for main (300). The term fee changed only on Advitha's branch, so it was merged normally (13000). With -s ours, the term fee would have stayed 12000. Revise: Merge Strategies.
Puzzle 3: A Sparse Working Folder
cd "$(mktemp -d)"
git init --quiet
mkdir -p backend web docs
touch README.md backend/App.java web/index.html docs/guide.md
git add .
git commit --quiet -m "Set up the project"
git sparse-checkout set backend
lsShow solution
cd "$(mktemp -d)"
git init --quiet
mkdir -p backend web docs
touch README.md backend/App.java web/index.html docs/guide.md
git add .
git commit --quiet -m "Set up the project"
git sparse-checkout set backend
lsREADME.md
backendWhy this output?
In cone mode, set backend keeps the backend folder and every file at the top level, so README.md stays while docs and web disappear from the working folder. They are still in the commit, and git sparse-checkout disable brings them back. Revise: Git Sparse Checkout.
What Your Score Means
| Score (out of 23) | What it means | What to do next |
|---|---|---|
| 20 to 23 | You know how Git works inside | Move on to Git in VS Code and IntelliJ IDEA, or take the Git Deep Dive Test |
| 16 to 19 | A pass, with a few gaps | Read the lessons linked from the questions you missed |
| Under 16 | Not yet | Reread the lessons behind your wrong answers, do Lab 4 on Git Labs, and take the test again |
Was this tutorial helpful?