Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Recall & Review
beginner
What is the HEAD pointer in Git?
HEAD is a reference that points to the current commit you have checked out in your working directory. It tells Git where you are in the project history.
Click to reveal answer
intermediate
What does it mean when HEAD is 'detached' in Git?
A detached HEAD means HEAD points directly to a commit instead of a branch. Changes made here are not linked to any branch until you create one or move HEAD.
Click to reveal answer
beginner
How does HEAD relate to branches in Git?
HEAD usually points to the latest commit on the current branch. When you switch branches, HEAD moves to point to the tip of that branch.
Click to reveal answer
intermediate
What happens if you commit while in a detached HEAD state?
The commit is created but not attached to any branch. It can be lost if you switch branches without saving it by creating a new branch.
Click to reveal answer
beginner
How can you check where HEAD is pointing in Git?
You can run the command git status or git symbolic-ref HEAD to see the current branch or commit HEAD points to.
Click to reveal answer
What does the HEAD pointer in Git usually point to?
AThe latest commit on the current branch
BThe first commit in the repository
CA random commit in the history
DThe remote repository
✗ Incorrect
HEAD normally points to the latest commit on the branch you have checked out.
What is a detached HEAD in Git?
AHEAD points to a remote branch
BHEAD points directly to a commit, not a branch
CHEAD is missing from the repository
DHEAD points to the working directory
✗ Incorrect
Detached HEAD means HEAD points to a commit directly, not to a branch.
Which command shows the current branch HEAD points to?
Agit push
Bgit init
Cgit status
Dgit clone
✗ Incorrect
git status shows the current branch and where HEAD points.
If you commit in a detached HEAD state and then switch branches without saving, what happens?
AThe commit may be lost
BThe commit is automatically added to the branch
CGit prevents switching branches
DThe commit is pushed to remote
✗ Incorrect
Commits made in detached HEAD can be lost if not saved by creating a branch.
When you switch branches, what happens to HEAD?
AIt points to the remote repository
BIt stays on the old branch
CIt points to the first commit
DIt moves to point to the tip of the new branch
✗ Incorrect
HEAD moves to the latest commit of the branch you switch to.
Explain what the HEAD pointer is in Git and why it is important.
Think about how Git tracks your current position in the project history.
You got /3 concepts.
Describe what happens when HEAD is detached and how to safely work in that state.
Consider what it means to be 'detached' and how to keep your changes safe.
You got /3 concepts.
Practice
(1/5)
1. What does the HEAD pointer in Git represent?
easy
A. The current commit your working directory is based on
B. The remote repository URL
C. The list of all branches
D. The stash of uncommitted changes
Solution
Step 1: Understand the role of HEAD in Git
HEAD points to the current commit that your working directory reflects.
Step 2: Differentiate HEAD from other Git concepts
HEAD is not related to remote URLs, branch lists, or stash; it tracks your current position in history.
Final Answer:
The current commit your working directory is based on -> Option A
Quick Check:
HEAD = current commit [OK]
Hint: HEAD always points to your current commit position [OK]
Common Mistakes:
Confusing HEAD with remote repository
Thinking HEAD lists branches
Assuming HEAD stores uncommitted changes
2. Which Git command correctly moves the HEAD pointer to the branch named feature?
easy
A. git merge feature
B. git checkout feature
C. git push feature
D. git commit feature
Solution
Step 1: Identify the command to switch branches
The git checkout command moves HEAD to the specified branch.
Step 2: Confirm other commands do not move HEAD
git commit creates commits, git push uploads changes, git merge combines branches but does not move HEAD directly.
Final Answer:
git checkout feature -> Option B
Quick Check:
Switch branch = git checkout [OK]
Hint: Use git checkout to move HEAD to another branch [OK]
Common Mistakes:
Using git commit to switch branches
Confusing git push with moving HEAD
Thinking git merge moves HEAD
3. Given the following commands run in order:
git checkout main
# HEAD points to main branch
git checkout -b new-feature
# Create and switch to new-feature branch
git commit -m "Add feature"
# Commit on new-feature branch
What does HEAD point to after these commands?
medium
A. No commit, HEAD is detached
B. The latest commit on the main branch
C. The initial commit of the repository
D. The latest commit on the new-feature branch
Solution
Step 1: Track HEAD movement through commands
Initially, HEAD points to main branch. Then git checkout -b new-feature creates and switches HEAD to new-feature branch.
Step 2: Commit on new-feature updates HEAD
The commit adds a new commit on new-feature branch, so HEAD points to this latest commit.
Final Answer:
The latest commit on the new-feature branch -> Option D
Quick Check:
HEAD follows current branch's latest commit [OK]
Hint: HEAD moves with branch switch and points to latest commit [OK]
Common Mistakes:
Assuming HEAD stays on main after branch creation
Thinking HEAD detaches after commit
Confusing initial commit with latest commit
4. You ran git checkout HEAD~1 but now your prompt shows (HEAD detached at ...). What is the problem?
medium
A. HEAD is detached because you checked out a commit, not a branch
B. HEAD is detached because you deleted the branch
C. HEAD is detached because the repository is corrupted
D. HEAD is detached because you pushed to remote
Solution
Step 1: Understand what git checkout HEAD~1 does
This command checks out the commit before the current HEAD, not a branch.
Step 2: Explain detached HEAD state
Checking out a commit directly detaches HEAD, meaning it points to a commit, not a branch.
Final Answer:
HEAD is detached because you checked out a commit, not a branch -> Option A
Quick Check:
Detached HEAD = checked out commit, not branch [OK]
Hint: Detached HEAD means checked out a commit, not a branch [OK]
Common Mistakes:
Thinking detached HEAD means repo corruption
Assuming branch was deleted
Confusing push with HEAD detachment
5. You want to move HEAD back two commits on the current branch but keep your working files unchanged. Which command should you use?
hard
A. git reset --hard HEAD~2
B. git checkout HEAD~2
C. git reset --soft HEAD~2
D. git revert HEAD~2
Solution
Step 1: Understand reset options
git reset --soft moves HEAD and branch pointer but keeps working directory unchanged.
Step 2: Compare other options
--hard resets files too, checkout detaches HEAD, revert creates a new commit undoing changes.
Final Answer:
git reset --soft HEAD~2 -> Option C
Quick Check:
Reset soft moves HEAD, keeps files [OK]
Hint: Use git reset --soft to move HEAD without changing files [OK]