Lesson 2 of 4 · Free to read
Exercises
Exercises — Version Control & Collaboration
Watch & learn
Course video
Course video
Keep a prompt log while you work. Speed without a trail is not a skill — it is luck.
How to use this file
- All exercises run against the PR review lab repo.
- AI prompts should be logged in
PROMPTS.md. - Use the
ghCLI wherever possible; the GitHub UI is allowed but not required.
Exercise 1 — Trace a commit to its blobs
Goal: starting from HEAD, traverse to a specific file's blob using only git cat-file.
Time: 20 minutes
Level: foundational
Modules touched: [07-version-control-and-collaboration]
Setup
- Use any small local repo (this one is fine).
Steps
git cat-file -p HEAD— note the tree SHA.git cat-file -p <tree-sha>— find a sub-tree or blob you care about.- Recurse until you reach a blob.
git cat-file -p <blob-sha>— confirm it matches the file content.- Write a short note in
learner-artifacts/<your-name>/git-walk.mdlisting each SHA you visited.
Success criteria
- Note file lists the SHAs at each level (commit → tree → … → blob).
- The final blob's content matches the actual file.
AI prompt hints
- "Ask Cursor: 'Given this
git cat-file -p HEADoutput, explain each line and where I'd go next to inspect [filename].'"
Solution sketch
The point is to demystify Git. Most learners realise the model is simpler than they thought — refs and objects, that's it.
Stretch
- Find two commits whose trees share blobs. Explain why that's possible.
Exercise 2 — Open a PR end-to-end with gh
Goal: fork the lab repo, branch, change, push, open a PR with a clear title/body, all from the terminal. Time: 25 minutes Level: foundational Modules touched: [07-version-control-and-collaboration]
Setup
gh auth status— confirm you're authenticated.gh repo fork <cohort-org>/pr-review-lab --clone(or usecode-examples/python/pr_review_lab/locally as a stand-in).
Steps
- Create a branch:
git switch -c feat/your-name-greeting. - Edit
README.md— add a single line under "Greetings" with your name. - Conventional commit:
git commit -am "docs(greetings): add <your-name>". - Push:
git push -u origin feat/your-name-greeting. gh pr create --title "docs(greetings): add <your-name>" --body "Adds a greeting line. See line N.".gh pr view— confirm the PR opened cleanly.
Success criteria
- PR is open against
main. - Title follows Conventional Commits.
- Body cites the specific line you changed.
AI prompt hints
- "Ask Cursor: 'Draft a Conventional Commit message for this diff.'"
- "Ask Cursor: 'Draft a PR body that explains the change in 3 lines and lists what to look at.'"
Solution sketch
The "what to look at" line in PR bodies is the cheapest reviewer-acceleration trick. Make it a habit.
Stretch
- Add a
--label docsto thegh pr createcall.
Exercise 3 — AI-assisted PR review
Goal: review the planted PR with Cursor (Reviewer/Editor persona) and post a verdict via gh pr review.
Time: 50 minutes
Level: intermediate
Modules touched: [07-version-control-and-collaboration, 02-ai-assisted-development]
Setup
- Check out PR #1 (or the local stand-in) in
code-examples/python/pr_review_lab/. - Activate the
70-reviewer-editorrule in Cursor.
Steps
- Read the diff yourself first. Write 2 bullets: "looks suspicious to me".
- Ask Cursor (using the Reviewer/Editor persona) for: strengths + 3 findings ranked by severity (blocker / major / minor / nit) + a suggested diff for the blocker.
- Compare AI's findings to your own list. Note disagreements.
- Decide your verdict. Post via
gh pr review <num> --comment "..."— include strengths, findings, and your reasoning. - Log every AI prompt in
PROMPTS.md.
Success criteria
gh pr reviewposted with structured comment.- Verdict includes: ≥2 strengths, 3 findings with severities, suggested diff for the blocker, and your reasoning where you disagreed with AI.
PROMPTS.mdhas ≥3 entries.
AI prompt hints
- "Act as a senior reviewer. List the strengths first. Then identify 3 findings: 1 blocker, 1 major, 1 nit. For the blocker, propose a suggested diff."
- "What cross-cutting concern (auth / logging / error handling / perf) is most likely missed here? Propose a test."
Solution sketch
The planted PR's blocker is usually security-related (e.g., missing input validation, secret in code) or correctness (off-by-one, edge case). The major is testing-related. The nit is style. Strong learners reject ≥1 AI suggestion with reasoning.
Stretch
- Repeat with two models (e.g., Claude vs GPT). Diff their reviews. Which would you act on first?
Exercise 4 — Resolve a 3-way merge conflict
Goal: resolve a planted conflict on the same lines from two branches; preserve both intents; ship green tests. Time: 35 minutes Level: intermediate Modules touched: [07-version-control-and-collaboration, 02-ai-assisted-development]
Setup
- In the lab repo, check out
feat/branch-a. Rungit merge feat/branch-b— conflict surfaces.
Steps
- Open the conflicted file in Cursor.
- Ask: "Summarise what side A is trying to achieve. Summarise side B. Propose a resolution that preserves both intents."
- Critically evaluate the proposed resolution. Edit if needed.
- Apply, save,
git add. - Run the test suite. Iterate until green.
git commitwith a Conventional Commit explaining the merge.
Success criteria
- Tests green.
- Commit message explains what each side wanted and how you combined them.
- Both sides' intents are reflected in the merged code (not silently dropped).
AI prompt hints
- "Summarise each conflict marker's intent in one sentence. Output as a bulleted list."
- "Propose a merge that preserves both intents. Output a unified diff only."
Solution sketch
The mistake is choosing one side or deleting both. The lesson is forcing yourself (and AI) to articulate intent first.
Stretch
- Write a Git hook (
prepare-commit-msg) that pre-populates a merge commit body with both sides' last commit messages.
Exercise 5 — Build a pre-merge bot (advanced)
Goal: write a gh + shell script that runs on a PR and posts a "ready to merge" check: tests green, commit messages valid Conventional, no TODOs added in the diff.
Time: 60 minutes
Level: advanced
Modules touched: [07-version-control-and-collaboration, 11-ci-cd]
Setup
- Local: install
ghandjq. - Use the lab repo or your own.
Steps
- Sketch the script: inputs (PR number), checks (3 above), output format (markdown comment).
- Implement in bash (or Python). Use
gh pr view <n> --json commits,filesto fetch metadata. - For "no new TODOs":
git diff origin/main...HEAD -- '*.py' '*.ts' | grep '^+.*TODO'. - Post via
gh pr comment <n> --body "$(cat report.md)". - Test on the planted PR #1.
Success criteria
- Script exits non-zero if any check fails.
- Comment posted to the PR with the 3 check results.
AI prompt hints
- "Draft the bash script that uses
gh+jqto check whether all commit messages in a PR follow Conventional Commits. Output the script only." - "Critique the script's edge cases. What does it miss?"
Solution sketch
A 30-line script. The discipline is in the spec, not the code. Strong learners use Cursor to spec the script first, then generate, then test on the planted PR.
Stretch
- Wrap it into a GitHub Action (jumps into Module 11).