Skip to content
Foxipa
Code Completion 4 Challenges

Complete the Git commands: Git Detached HEAD: Inspecting Commits Without Moving a Branch

In a disposable repository, create at least two commits on `main` and record the tip object ID. Use `git switch --detach HEAD~1` to detach at a known earlier commit. Record `git rev-parse HEAD`, `git rev-parse --symbolic-full-name HEAD`, `git rev-parse --abbrev-ref HEAD`, `git status --short --branch`, and the unchanged `main` tip. Then make one controlled empty commit while detached and prove that HEAD advances while `main` remains unchanged. Next, create a second disposable repository and run `git switch --detach main` at the branch tip; prove that equal object IDs do not make HEAD attached. Finally, run `git switch main` and prove that HEAD is symbolic again. Do not use reflogs or recovery techniques in this exercise; those belong to the later investigation/recovery phase. Success requires state evidence rather than only command output: identify the selected commit, prove that HEAD is detached, prove that the named branch tip did not move during the detached commit, and then prove reattachment by observing `refs/heads/main` as HEAD’s symbolic target. Use disposable repositories whenever an experiment creates commits that you do not intend to keep on a named branch.

Intermediate ~6 min read

Challenge 1

Complete the Git command to change the checked-out branch.

bash Your answer
git  --detach HEAD~1

Press Ctrl⌘Enter to check your answer

Challenge 2

Complete the Git command to resolve or verify a revision.

bash Your answer
git  HEAD

Press Ctrl⌘Enter to check your answer

Challenge 3

Complete the Git command to resolve or verify a revision.

bash Your answer
git  --symbolic-full-name HEAD

Press Ctrl⌘Enter to check your answer

Challenge 4

Complete the Git command to resolve or verify a revision.

bash Your answer
git  --abbrev-ref HEAD

Press Ctrl⌘Enter to check your answer