CompCode Academy

Lesson 2 of 4 · Free to read

Exercises

Exercises — Version Control & Collaboration

Watch & learn

Course video

Open on YouTube
Git and GitHub for Beginners (freeCodeCamp) — Commit, branch, push — the baseline every AI workflow needs.

Course video

Open on YouTube
GitHub Actions Tutorial — CI/CD Pipeline — Pipelines that gate AI-generated changes.

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 gh CLI 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

  1. git cat-file -p HEAD — note the tree SHA.
  2. git cat-file -p <tree-sha> — find a sub-tree or blob you care about.
  3. Recurse until you reach a blob.
  4. git cat-file -p <blob-sha> — confirm it matches the file content.
  5. Write a short note in learner-artifacts/<your-name>/git-walk.md listing 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 HEAD output, 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

Steps

  1. Create a branch: git switch -c feat/your-name-greeting.
  2. Edit README.md — add a single line under "Greetings" with your name.
  3. Conventional commit: git commit -am "docs(greetings): add <your-name>".
  4. Push: git push -u origin feat/your-name-greeting.
  5. gh pr create --title "docs(greetings): add <your-name>" --body "Adds a greeting line. See line N.".
  6. 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 docs to the gh pr create call.

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

Steps

  1. Read the diff yourself first. Write 2 bullets: "looks suspicious to me".
  2. Ask Cursor (using the Reviewer/Editor persona) for: strengths + 3 findings ranked by severity (blocker / major / minor / nit) + a suggested diff for the blocker.
  3. Compare AI's findings to your own list. Note disagreements.
  4. Decide your verdict. Post via gh pr review <num> --comment "..." — include strengths, findings, and your reasoning.
  5. Log every AI prompt in PROMPTS.md.

Success criteria

  • gh pr review posted 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.md has ≥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. Run git merge feat/branch-b — conflict surfaces.

Steps

  1. Open the conflicted file in Cursor.
  2. Ask: "Summarise what side A is trying to achieve. Summarise side B. Propose a resolution that preserves both intents."
  3. Critically evaluate the proposed resolution. Edit if needed.
  4. Apply, save, git add.
  5. Run the test suite. Iterate until green.
  6. git commit with 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 gh and jq.
  • Use the lab repo or your own.

Steps

  1. Sketch the script: inputs (PR number), checks (3 above), output format (markdown comment).
  2. Implement in bash (or Python). Use gh pr view <n> --json commits,files to fetch metadata.
  3. For "no new TODOs": git diff origin/main...HEAD -- '*.py' '*.ts' | grep '^+.*TODO'.
  4. Post via gh pr comment <n> --body "$(cat report.md)".
  5. 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 + jq to 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).

New free lessons and course updates. Unsubscribe from any email.