02 Exercise: Git Pointers and Branches
Instructions
This interactive quiz tests your understanding of Git branches as pointers. Each question shows a Git graph with commits, branches, HEAD, and/or tags. Study each graph carefully before selecting your answer.
Topics covered:
- Branch creation and switching
- How HEAD, branches, and tags work as pointers
- Fast-forward merges and divergent branches
- Detached HEAD state
- Remote-tracking branches and cleanup workflows
Each question has exactly one correct answer. Focus on understanding what the pointers tell you about the Git state.
You’re on the main branch and run git checkout -b feature/new-ui. What does the Git graph look like immediately after this command?
Before:
"Add login" "Fix bug" "Add dashboard"
↓ ↓ ↓
a1b2c3d ← e4f5g6h ← i7j8k9l
↑
main ← HEAD
After creating feature/new-ui, you make a commit. What does the graph look like?
Before commit:
a1b2c3d ← e4f5g6h ← i7j8k9l
↑
main
feature/new-ui ← HEAD
You make two more commits on feature/new-ui. What’s the state now?
Starting from:
a1b2c3d ← e4f5g6h ← i7j8k9l ← p9q8r7s
↑ ↑
main feature/new-ui ← HEAD
After 2 more commits:
You run git checkout main. What happens to the pointers?
Before checkout:
a1b2c3d ← e4f5g6h ← i7j8k9l ← p9q8r7s ← t1u2v3w ← x4y5z6a
↑ ↑
main feature/new-ui ← HEAD
While on main, you run git merge feature/new-ui and Git performs a “fast-forward” merge. What’s the result?
Before merge:
a1b2c3d ← e4f5g6h ← i7j8k9l ← p9q8r7s ← t1u2v3w ← x4y5z6a
↑ ↑
main ← HEAD feature/new-ui
After the merge, you create a tag: git tag -a v1.0 -m "Release 1.0". Where does the tag pointer point?
Before tag:
a1b2c3d ← e4f5g6h ← i7j8k9l ← p9q8r7s ← t1u2v3w ← x4y5z6a
↑
main ← HEAD
feature/new-ui
You switch to main and make a commit. Meanwhile, feature/new-ui stays where it is. What’s the state?
Starting state:
a1b2c3d ← e4f5g6h ← i7j8k9l ← p9q8r7s ← t1u2v3w ← x4y5z6a
↑
main ← HEAD
feature/new-ui
(v1.0)
After: git checkout main, then make a commit
Starting from Question 7’s result, you now switch to feature/new-ui and make a new commit. What does the repository look like?
Starting state (from Q7):
a1b2c3d ← e4f5g6h ← i7j8k9l ← p9q8r7s ← t1u2v3w ← x4y5z6a ← b7c8d9e
↑ ↑
(v1.0) main ← HEAD
feature/new-ui
Commands run:
git checkout feature/new-ui
echo "new feature code" >> app.js
git add app.js
git commit -m "Add new UI feature"
What's the result?
You run git checkout x4y5z6a (the commit tagged v1.0). What state is Git in?
Before checkout:
b7c8d9e
↑
main ← HEAD
/
a1b2c3d ← e4f5g6h ← i7j8k9l ← p9q8r7s ← t1u2v3w ← x4y5z6a ←
↑ \
(v1.0) f1g2h3i
↑
feature/new-ui
You rename a branch with git branch -m old-name new-name. What actually changes?
Before rename:
↱ b7c8d9e
/ ↑
a1b2c3d ← e4f5g6h ← i7j8k9l ← p9q8r7s ← t1u2v3w ← x4y5z6a main
↑ ↖
(v1.0) f1g2h3i
↑
feature/old-name ← HEAD
You run git branch -a and see this output. What are the three types of references shown?
$ git branch -a
main
feature/new-feature
remotes/origin/main
remotes/origin/feature/old-pr
You run git fetch origin. What does this command update?
Before fetch:
GitHub (origin):
main → x4y5z6a (latest commit)
Your local Git:
main → i7j8k9l (outdated)
remotes/origin/main → i7j8k9l (outdated bookmark)
After fetch:
A PR was merged and the feature branch was deleted on GitHub. You run git branch -a locally. What do you see?
GitHub (origin):
main (only branch that exists)
Your local Git hasn't fetched yet:
What does git fetch --prune do differently from git fetch?
Situation:
- GitHub deleted feature/old-pr
- Your local Git still has remotes/origin/feature/old-pr
You run: git fetch --prune
You just merged a PR on GitHub and the feature branch was auto-deleted. You run git checkout main then git pull --prune. What happens?
Before:
GitHub: main → x4y5z6a (has merged PR)
feature/old-pr deleted
Local: main → i7j8k9l (outdated)
feature/old-pr → p9q8r7s (still exists locally)
remotes/origin/main → i7j8k9l (outdated)
remotes/origin/feature/old-pr → p9q8r7s (stale!)
After git pull --prune:
According to the lecture’s “bookmark analogy,” what do remote-tracking branches represent?
GitHub (the websites) has:
- main branch
- feature/xyz branch
Your local Git has:
- Local branches (main, feature/xyz)
- Remote-tracking branches (remotes/origin/main, remotes/origin/feature/xyz)
You want Git to automatically remove stale remote-tracking branches every time you fetch. What should you configure?
You want to see which local branches have been merged into main before deleting them. What command shows this?
Your PR was merged with “Squash and merge” on GitHub. The branch was deleted there. Now you try to delete your local branch:
$ git branch -d feature/squashed
error: The branch 'feature/squashed' is not fully merged.
Why does Git say this, and what should you do?
Your PR was merged using “Create a merge commit” (not squash) and GitHub auto-deleted the remote branch. What’s the complete cleanup workflow?
Starting state:
- GitHub: main (updated with your PR using merge commit), feature/xyz deleted
- Local: main (outdated), feature/xyz (still exists),
remotes/origin/feature/xyz (stale)