Git Level 4 Test

Updated · 9 min read

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

Level 4 test: 20 questions

20 questions
1What is an object's ID in Git computed from?
2Two files in different folders have exactly the same content. How many blobs does Git store for them?
3What does a commit object contain?
4What is stored in .git/refs/heads/main (in the files format)?
5During a merge conflict, what does stage 2 of a file in the index hold?
6What does git gc do?
7Which plumbing command turns the index into a tree object?
8How do you make Git use a different email address only in repositories under ~/work/?
9Which .gitattributes line keeps gradlew with LF line endings on every computer?
10A pre-commit hook exits with code 1. What happens?
11Why aren't hooks in .git/hooks shared when you push?
12What does git clone --filter=blob:none leave out?
13What does Git LFS store in the repository for a large tracked file?
14What does the commit-graph file speed up?
15What does a superproject store for a submodule?
16Which can be checked out in two worktrees at the same time?
17Which settings make Git sign commits with an SSH key?
18Which pair of commands sends three commits as files and applies them as commits elsewhere?
19What is the difference between -s ours and -X ours in git merge?
20What does rerere record?

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

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 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"; done
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 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"; done
Output
commit
tree
blob
tag
Why 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

Terminal
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.txt
Show solution
Terminal
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.txt
Output
Auto-merging fees.txt
Term fee: 13000
Exam fee: 800
Late fee: 300
Why 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

Terminal
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
ls
Show solution
Terminal
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
ls
Output
README.md
backend
Why 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 meansWhat to do next
20 to 23You know how Git works insideMove on to Git in VS Code and IntelliJ IDEA, or take the Git Deep Dive Test
16 to 19A pass, with a few gapsRead the lessons linked from the questions you missed
Under 16Not yetReread the lessons behind your wrong answers, do Lab 4 on Git Labs, and take the test again

Was this tutorial helpful?