Applied Labs & Evaluation Rubrics
Scenario-based exercises for resolving complex Git states and the standard rubric for evaluating repository hygiene.
Practical Scenarios: Advanced Git Recovery
Mastering Git requires intentionally breaking your local repository and learning how to recover the state without panicking. The following two labs simulate common engineering roadblocks.
Lab 1: Escaping the “Detached HEAD” State
The Scenario: You wanted to see what the code looked like two weeks ago. You found the commit hash (a1b2c3d) and ran git checkout a1b2c3d. You made some experimental changes and committed them. Suddenly, Git warns you that you are in a “detached HEAD” state, and if you switch branches, your new commits will be lost.
The Underlying Cause: The HEAD pointer normally rests on a branch reference (like main). When you check out a specific commit hash, HEAD detaches from the branch and points directly to the commit object. Any new commits you make are orphaned—they belong to no branch.
The Resolution: To save your work, you must assign a branch reference to your current, detached state.
# 1. Create a new branch originating from your current detached state and switch to it
git checkout -b experimental-recovery
# 2. Your work is now safely anchored to a branch.
# You can now merge or rebase this branch back into your main workflow.