Git Refresh Test

Updated · 10 min read
mediumGit 2.53gittestquizrefreshmodern-gitassessment

Someone who learned to drive twenty years ago drives perfectly well, yet a new car surprises them: it keeps itself in its lane, the handbrake is a button, and the dashboard asks for an update. This test is for developers in that position with Git. You use it every day, perhaps with the same five commands you learned years ago. It checks the newer commands and settings that make Git safer, and the topics that interviews ask about most.

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 three areas, undoing, modern commands, pulling and force pushing, rebase, recovery and debugging.

Part 1: 20 Questions

Refresh test: 20 questions

20 questions
1Which command replaces git checkout -b feature/books?
2Which command replaces git reset HEAD fees.txt for unstaging a file?
3Which command gets fees.txt back as it was in v1.0, without switching branches?
4What does git add actually store?
5A teammate has already pulled your branch. Which undo is safe?
6What does setting pull.rebase true change?
7Why use --force-if-includes together with --force-with-lease?
8What does push.autoSetupRemote true do?
9What does merge.conflictStyle zdiff3 add to conflict markers?
10What does git rebase --update-refs do?
11What does git rebase -i --autosquash do with commits named "fixup! Add the late fee"?
12You committed to main by mistake. Nothing is pushed. Which pair of commands moves the commit to a new branch?
13Which command finds commits you "lost" with a hard reset?
14What does git maintenance start do?
15Which merge strategy has been Git's default since version 2.34?
16Which command creates a second working folder for another branch, without stashing?
17What makes git bisect run useful?
18How do you make git blame skip a commit that only reformatted the code?
19Which signing method needs no extra software beyond OpenSSH?
20Which clone gets all commits but downloads old file contents only when needed?

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: Conflict Markers with the Base

Terminal
cd "$(mktemp -d)"
git init --quiet
git config merge.conflictStyle zdiff3
echo 'Late fee: $250' > fees.txt
git add fees.txt
git commit --quiet -m "Add the late fee"
git switch --quiet -c advitha
echo 'Late fee: $275' > fees.txt
git commit --quiet -am "Set the late fee to 275"
git switch --quiet main
echo 'Late fee: $300' > fees.txt
git commit --quiet -am "Set the late fee to 300"
git merge --quiet advitha > /dev/null
cat fees.txt
Show solution
Terminal
cd "$(mktemp -d)"
git init --quiet
git config merge.conflictStyle zdiff3
echo 'Late fee: $250' > fees.txt
git add fees.txt
git commit --quiet -m "Add the late fee"
git switch --quiet -c advitha
echo 'Late fee: $275' > fees.txt
git commit --quiet -am "Set the late fee to 275"
git switch --quiet main
echo 'Late fee: $300' > fees.txt
git commit --quiet -am "Set the late fee to 300"
git merge --quiet advitha > /dev/null
cat fees.txt
Output
<<<<<<< HEAD
Late fee: $300
||||||| ca6af41
Late fee: $250
=======
Late fee: $275
>>>>>>> advitha
Why this output?

With zdiff3, the conflict shows three versions: ours (300) after <<<<<<< HEAD, the common ancestor (250) after ||||||| and the base commit's short ID (yours will differ, so it doesn't count when marking), and theirs (275) after =======. Seeing that the base was 250 shows that both sides raised the fee, which helps decide the right value. Revise: Useful Git Settings.

Puzzle 2: Stacked Branches Move Together

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/api
echo "API" > api.txt
git add api.txt
git commit --quiet -m "Add the fee API"
git switch --quiet -c feature/ui
echo "UI" > ui.txt
git add ui.txt
git commit --quiet -m "Add the fee page"
git switch --quiet main
echo 'Exam fee: $800' >> fees.txt
git commit --quiet -am "Add the exam fee"
git switch --quiet feature/ui
git rebase --quiet --update-refs main
git log --format="%s%d"
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/api
echo "API" > api.txt
git add api.txt
git commit --quiet -m "Add the fee API"
git switch --quiet -c feature/ui
echo "UI" > ui.txt
git add ui.txt
git commit --quiet -m "Add the fee page"
git switch --quiet main
echo 'Exam fee: $800' >> fees.txt
git commit --quiet -am "Add the exam fee"
git switch --quiet feature/ui
git rebase --quiet --update-refs main
git log --format="%s%d"
Output
Add the fee page (HEAD -> feature/ui)
Add the fee API (feature/api)
Add the exam fee (main)
Add the term fee
Why this output?

Rebasing feature/ui replayed both of its commits onto main. Because of --update-refs, feature/api, which pointed at the first of those commits, moved to the rebased copy, so it still sits right under feature/ui. Without the option, feature/api would have stayed on the old commit. Revise: Rebase Onto and Stacked Branches.

Puzzle 3: Restore from an Older Commit

Terminal
cd "$(mktemp -d)"
git init --quiet
echo 'Late fee: $250' > fees.txt
git add fees.txt
git commit --quiet -m "Add the late fee"
echo 'Late fee: $300' > fees.txt
git commit --quiet -am "Raise the late fee"
git restore --source=HEAD~1 fees.txt
cat fees.txt
git status --short
Show solution
Terminal
cd "$(mktemp -d)"
git init --quiet
echo 'Late fee: $250' > fees.txt
git add fees.txt
git commit --quiet -m "Add the late fee"
echo 'Late fee: $300' > fees.txt
git commit --quiet -am "Raise the late fee"
git restore --source=HEAD~1 fees.txt
cat fees.txt
git status --short
Output
Late fee: $250
 M fees.txt
Why this output?

git restore --source=HEAD~1 wrote the older version into the working folder only. The branch didn't move, so git status shows the file as modified but not staged ( M). Add --staged --worktree to restore both the staging area and the file. (This puzzle's last two commands both print.) Revise: Git Restore.

What Your Score Means

Score (out of 23)What it meansWhat to do next
20 to 23Your Git is up to dateTry the Git Deep Dive Test, or the Git Mock Interview
16 to 19Mostly up to dateRead the lessons linked from the questions you missed
Under 16Time for a refreshRevise the lessons on the topics you missed, starting with Working Tree, Staging Area and Repository, then take the test again

Was this tutorial helpful?