Lesson 9 of 9 · about 45 minutes
Capstone: the full loop
Issue → agent branch → pull request → green CI → main. On your own, start to finish.
penguins-lab from a GitHub issue to a merged, CI-tested pull request, with Claude Code doing the work in its own worktree. That is the workflow you'll use from now on.Part 1 — Warm up from memory
These questions mix all eight lessons on purpose. Switching between topics is harder than drilling one, and that difficulty is what builds long-term memory. Don't scroll back. Guess, then read the explanation.
On main you run git switch -c add-summary-stats. Where do the two branches point?
- Both at the same commit
- New branch at empty commit
- main moves to new commit
- New branch at first commit
A branch is a movable pointer. A new one starts at the commit you're on, and nothing moves until you commit (Lesson 1).1
main hasn't moved since you branched. What does git merge add-summary-stats on main do?
- Slides main forward, no commit
- Creates a two-parent merge commit
- Refuses until you push first
- Duplicates the branch's commits again
No divergent work means a fast-forward: Git just moves the pointer (Lesson 3).2
git branch -d old-idea answers "not fully merged". What does that tell you?
- Its commits aren't reachable from HEAD
- The branch was already deleted remotely
- You must push it before deleting
- The branch name contains invalid characters
-d only deletes a branch "fully merged in its upstream branch, or in HEAD". -D forces it and throws the work away (Lesson 3).3
Why use git push -u origin add-summary-stats the first time you push?
- Sets upstream so plain push works
- Uploads every branch in the repository
- Merges the branch into origin main
- Unlocks the branch for other collaborators
-u records the upstream, "used by argument-less git-pull and other commands" (Lesson 4).4
What does git diff main...add-summary-stats show?
- only changes made on the branch
- every difference between the two tips
- commits on main since branching off
- files changed by your last commit
The three-dot form diffs from the merge base to the branch. That's exactly what a pull request shows (Lessons 2 and 4).5
Claude made nine small commits on an agent branch. Which merge method gives main one tidy commit?
- Squash and merge it
- Create a merge commit
- Rebase and merge it
- Fast-forward main locally first
Squash suits a PR that "represents one logical change, especially if the branch includes many small fixup commits" (Lesson 4).6
A workflow triggered by pull_request runs your tests against which code?
- the merged result with base
- the head branch tip only
- the base branch before merging
- the newest release on GitHub
actions/checkout checks out the PR merge ref, so "CI tests run against the merged result, not just the head branch alone" (Lesson 5).7
Claude deleted a data file with rm through Bash. Will /rewind bring it back?
- No, Bash changes aren't tracked
- Yes, checkpoints capture every change
- Yes, if within thirty days
- Only when on main branch
"Checkpointing does not track files modified by Bash commands." Checkpoints are "not a replacement for version control." Commit often (Lesson 6).8
git worktree add ../b feature-x refuses because feature-x is checked out in your main folder. Why?
- A branch lives in one worktree
- Worktrees must sit inside the repo
- Worktrees only work on new branches
- You must commit to main first
By default add refuses a branch that's already checked out in another worktree (Lesson 7).9
In Claude Code, what does /branch experiment create?
- a copy of the conversation
- a new git branch locally
- a remote branch on GitHub
- a new git worktree folder
It's a naming trap: /branch branches the conversation, not git (Lesson 6).10
Type it, don't pick it
Create add-summary-stats and switch to it in one command.
You're on add-summary-stats. Show only the changes this branch made since it left main.
Publish add-summary-stats to GitHub for the first time and set its upstream.
Squash-merge the current branch's pull request and delete the branch, using the GitHub CLI.
Start Claude Code in a new isolated worktree named add-summary-stats.
List every worktree attached to this repository.
Part 2 — The lab: one task, the whole loop
The task: add a summarize_by_species(df) function to clean.py that returns mean bill length and body mass per species, plus a test. Claude writes it. You run the process.
If a leftover local branch survives step 9, git branch -d may say "not fully merged". A squash merge puts a new commit on main, so the branch's original commits aren't reachable from it. Once you've confirmed the PR merged, git branch -D is the right call.36
Stretch: two agents at once
Open two terminals in penguins-lab. Run claude -w add-species-plot in one and claude -w add-island-counts in the other. Brief both, then run each through steps 4–9. If both touch README.md or clean.py, the second PR will hit a merge conflict once the first merges. CI won't even start: "Workflows will not run on pull_request activity if the pull request has a merge conflict."7 Resolve it inside the second worktree:
$ git fetch origin
$ git merge origin/main # conflict markers appear
# edit the files: keep both changes, delete <<<<<<< ======= >>>>>>>
$ git add README.md
$ git commit # seals the merge
$ git push # CI re-runs on the PR
Git's docs describe this exact sequence: "Edit the files into shape and git add them… Use git commit… to seal the deal."2 You can also ask the agent in that worktree to do the merge and explain each conflict before resolving it.
Part 3 — Where to go next
You now have the skills. Wisdom comes from using them with other people.
- Ask practitioners. GitHub Community discussions is the official, moderated forum for Actions, pull request, and branch protection questions. The Anthropic Discord is where Claude Code users compare branch and worktree habits. Search the Stack Overflow
gittag before asking. Most git questions already have answers there. - Keep practising. GitHub Skills runs free, hands-on courses inside real repositories: Review pull requests, Resolve merge conflicts, Hello GitHub Actions, and Test with Actions. Learn Git Branching is a bigger version of this course's simulator.
- Make it a habit. For your next real assignment, open an issue first and run the loop above. Keep the Claude workflow card and cheat sheet beside you until you stop needing them.
Sources
- Chacon & Straub, Pro Git, §3.1 Branches in a Nutshell.
- Pro Git, §3.2 Basic Branching and Merging; Git reference, git-merge — how to resolve conflicts.
- Git reference, git-branch
-d/-D. - Git reference, git-push
--set-upstream. - Git reference, git-diff (three-dot form); GitHub Docs, three-dot diffs in pull requests.
- GitHub Docs, About pull request merges; Deleting and restoring branches in a pull request.
- GitHub Docs, Events that trigger workflows — pull_request.
- Claude Code docs, Checkpointing (limitations; not a replacement for version control).
- Git reference, git-worktree.
- Claude Code docs, Commands (
/branch). - Claude Code docs, Run parallel sessions with worktrees.
- GitHub CLI manual, gh issue create.
- Claude Code docs, Best practices — explore, plan, code.
- Claude Code docs, Common workflows — create pull requests; Settings — attribution.
- GitHub Docs, Linking a pull request to an issue.
- GitHub Docs, GitHub flow.