๐Ÿ Python for Everyone

← Back to all chapters

Chapter 29 of 33 Intermediate 65 min read

GitHub & Collaboration

Chapter 28 covered local git — commits, branches, merging, rebase, resolving conflicts, undoing changes. All of that happens on your own machine, in a repository nobody else can see. This chapter is about the layer on top: sharing that history with other people. GitHub doesn't replace git — it's a hosted copy of your repository, plus a set of tools (pull requests, reviews, issues) built around the act of moving commits between machines and getting other humans to look at them before they land.

How to read this chapter

Chapter 28 ended with a repository that lives entirely on one computer. Every commit, every branch, every bit of history is real — but if that laptop dies, so does the project, and nobody else can see any of it. This chapter is about the fix: a remote, a copy of the repository living somewhere else, and everything built around sharing it with other people.
Sub-topic 1 of 6

1. Remotes

At a glance
  • A remote is just another copy of the repository that your local git knows how to talk to — usually hosted on GitHub, but it can be anywhere reachable over a URL or filesystem path.
  • origin is a name, not a keyword — it's the conventional label git gives the remote you cloned from, and nothing stops you from renaming or adding more.
  • fetch downloads a remote's history without touching your working branch; pull does a fetch and then immediately merges it into the branch you're on.
Why this matters: almost every confusing "my push got rejected" or "my pull did something I didn't expect" moment comes down to not knowing which of these two operations actually ran, and what a remote even is underneath the GitHub UI.
What is... a remote? A remote is a named reference to another copy of the same repository, stored as a URL (or, as in this chapter's examples, a local filesystem path). Your local git doesn't automatically know about anything outside your machine — git remote add <name> <url> is the one command that tells it "there's another copy of this repo over there, and I want to call it <name>."

GitHub itself is nothing more than a hosting service for bare git repositories, plus a web UI built on top. To prove that honestly — not just assert it — every example below runs against a real second repository on this machine, created with git init --bare, which behaves exactly like a GitHub remote would: it has no working directory, only the raw commit history, and it only accepts pushes and serves fetches.

terminal
# stand in for "a repo on GitHub" -- a real bare repo, verified end to end
git init --bare upstream-remote.git

# a normal, local project
git init recipe-box
cd recipe-box
git checkout -b main
echo "# Recipe Box" > README.md
git add README.md
git commit -m "Initial commit"

# connect the local repo to the "remote"
git remote add origin ../upstream-remote.git
git remote -v
actual output of git remote -v
origin	../upstream-remote.git (fetch)
origin	../upstream-remote.git (push)

Two lines for one remote — git tracks fetch and push as separate URLs for the same name, since some setups genuinely do point them at different places (rare, but the split exists on purpose). -u on the first push does one more thing worth calling out: it sets up a tracking branch, linking local main to origin/main so later git push/git pull calls don't need the remote and branch spelled out every time.

terminal
git push -u origin main
actual output of git push -u origin main
To ../upstream-remote.git
 * [new branch]      main -> main
branch 'main' set up to track 'origin/main'.

Thought process: before touching GitHub at all, the goal is proving what a remote actually is with a setup nobody has to take on faith -- a real bare repo, not a screenshot of github.com. git init --bare is the right stand-in because it's genuinely the same shape as what GitHub hosts: no working directory, just the raw object history, reachable only by push/fetch.

Write the prompt you'd give an AI assistant to build this:

Show a strong version of this prompt
Using only git commands in a terminal, create a bare repository called upstream-remote.git with `git init --bare` to act as a stand-in for a GitHub remote. Then create a separate normal git repository called recipe-box, add a README.md, commit it on a branch named main, connect it to the bare repo with `git remote add origin ../upstream-remote.git`, and push it with `git push -u origin main` so the branch is set up to track origin/main. Show the output of `git remote -v` and the push command.

With the remote connected, here's the actual difference between fetch and pull — the single most common source of confusion for anyone new to remotes. Someone else pushes a change; verify what each command does, one at a time:

terminal
# (a teammate's clone pushed a new commit to origin/main in the meantime)

git fetch origin
actual output of git fetch origin
From ../upstream-remote
   73532d6..056af9b  main       -> origin/main

Notice what didn't happen: the local main branch and the working directory are completely untouched. fetch only updates git's local record of where origin/main points — it downloads the new commit into the repository's object database and moves the remote-tracking pointer, nothing more. This is confirmed directly:

terminal
git log --oneline               # local main -- unchanged
git log --oneline origin/main   # what fetch downloaded -- one commit ahead
actual output -- local main vs. origin/main after fetch
73532d6 Add feature X
b60638f Initial commit

056af9b Teammate pushes a change
73532d6 Add feature X
b60638f Initial commit

pull is the command that actually changes your working branch — it's fetch immediately followed by a merge (or rebase, with the right flag) of the fetched commits into the branch you're on:

terminal
git pull origin main
actual output of git pull origin main
From ../upstream-remote
 * branch            main       -> FETCH_HEAD
   056af9b..89ad16c  main       -> origin/main
Updating 056af9b..89ad16c
Fast-forward
 app.py | 1 +
 1 file changed, 1 insertion(+)

This one was a fast-forward — the local branch had no commits of its own beyond what the remote already had, so git just slides the branch pointer forward, no merge commit needed. Chapter 28 already covered what happens when both sides have diverging commits instead (a real merge or conflict) — the exact same rules apply here, pull is just fetch plus that same merge machinery, aimed at a remote instead of another local branch.

fetch vs. pull, side by side
git fetch origin
  -> downloads new commits, updates origin/main
  -> your current branch: UNCHANGED

git pull origin main
  -> downloads new commits (= fetch)
  -> THEN merges them into your current branch
  -> your current branch: UPDATED
What is... a tracking branch? A tracking branch is a local branch that's linked to a specific remote branch, so git knows what "the remote" means without being told every time. git push -u origin main (or git branch --set-upstream-to) sets this up once; afterward, plain git push and git pull with no arguments know to talk to origin/main automatically. git status also uses it to report things like "Your branch is 2 commits behind origin/main."
Go Deeper: why would you ever fetch without pulling?

Fetching first, then looking at what changed (git log origin/main, or git diff main origin/main) before deciding whether to merge is a genuinely safer habit on a shared branch — it lets you review incoming changes before they touch your working directory, rather than merging blind. Many experienced developers fetch by default and only pull (or run git merge origin/main manually) once they've actually looked.

Quick recap
  • A remote is another copy of the repository git knows how to reach; origin is a name, not a special keyword.
  • git remote add <name> <url> connects a repo; git push -u sets up a tracking branch on first push.
  • fetch downloads without touching your branch; pull downloads and merges in one step.
Sub-topic 2 of 6

2. Forking vs. cloning

At a glance
  • Cloning copies a repository to your machine; it says nothing about permissions — you clone any repo you can already read.
  • A fork is a full copy of someone else's GitHub repository, made under your own account, that you have full write access to.
  • Fork when you don't have (and won't get) push access to the original; clone directly when you already do — your own projects, or a team repo you're a collaborator on.
Why this matters: "should I fork this or just clone it?" is one of the first genuinely confusing GitHub questions for anyone coming from local-only git, because the two look similar (both end with code on your machine) but solve completely different problems.
What is... a fork? A fork is a copy of a repository that GitHub creates on GitHub itself, under your account, with its own remote URL you fully control. It's not a local operation — forking happens on github.com (a button on the repo page), and only afterward do you git clone your fork down to your own machine, exactly like cloning any other repository.

The practical difference shows up the moment you try to push. Cloning a repository you don't have write access to still lets you commit locally — git doesn't stop you — but git push against the original will fail with a permissions error, because GitHub (not git) is enforcing who can write to that specific remote. A fork sidesteps this entirely: it's a full copy under your own account, so you can push to it freely, then propose your changes back to the original via a pull request (Sub-topic 3).

Illustrative text mockup โ€” not a real screenshot

GitHub's actual repo page renders this as a styled button with a live fork count; this is a plain-text description of what it does, not the real UI.

github.com/octocat/some-project

  [ Fork ]  1.2k          [ Star ]  8.4k          [ Watch ]  340

  Clicking "Fork" creates a full copy of this repository
  under YOUR account:

    github.com/octocat/some-project   (original -- "upstream")
              |
              |  Fork button (on GitHub, not a git command)
              v
    github.com/your-username/some-project   (your fork -- you own this)

  You still need `git clone` to get YOUR fork onto your
  own machine -- forking alone only creates the copy on GitHub.

Once your fork exists (on GitHub) and you've cloned it (onto your machine), your local origin points at your fork by default — not the original project. To stay current with the original as it keeps moving, add it as a second remote, conventionally named upstream:

terminal
# after: fork on GitHub, then `git clone` your fork locally
git remote -v
actual output -- origin points at YOUR fork, not the original
origin	/path/to/my-fork-remote.git (fetch)
origin	/path/to/my-fork-remote.git (push)
terminal
git remote add upstream /path/to/upstream-remote.git
git remote -v
actual output -- now two remotes, origin (your fork) and upstream (the original)
origin	/path/to/my-fork-remote.git (fetch)
origin	/path/to/my-fork-remote.git (push)
upstream	/path/to/upstream-remote.git (fetch)
upstream	/path/to/upstream-remote.git (push)

Syncing a fork is now a normal fetch-and-merge, just aimed at upstream instead of origin, followed by a push back to your own fork so GitHub shows it up to date too:

terminal
git fetch upstream
git merge upstream/main -m "Merge upstream/main into fork"
git push origin main
actual output -- upstream had moved ahead one commit; fast-forwarded, then pushed to the fork
From /path/to/upstream-remote
 * [new branch]      main       -> upstream/main
Updating 89ad16c..e264451
Fast-forward (no commit created; -m option ignored)
 app.py | 1 +
 1 file changed, 1 insertion(+)
To /path/to/my-fork-remote.git
   89ad16c..e264451  main -> main

Because the merge was a clean fast-forward, git ignored the -m message entirely (there's nothing to attach it to — no new commit was created, the branch pointer just moved). If your fork had its own commits that diverged from upstream instead, this would behave exactly like any other diverging merge from Chapter 28: a real merge commit, or a conflict to resolve by hand.

Thought process: keeping a fork in sync is really just "fetch from a remote you don't normally push to, then push the result to the one you do" -- naming the second remote `upstream` is convention, not a requirement, but it's the convention every real project assumes, so it's worth using even in a toy example.

Write the prompt you'd give an AI assistant to build this:

Show a strong version of this prompt
I have a local clone of my GitHub fork, where `origin` already points at my fork. The original project I forked from is at a different URL. Show me the exact git commands to: (1) add the original project as a second remote named `upstream`, (2) fetch its latest changes without touching my working branch, (3) merge upstream's main branch into my local main, and (4) push the result back to my fork (origin) so GitHub shows my fork up to date. Explain what happens differently if the merge is a clean fast-forward versus if my fork has its own commits that diverged from upstream.
Go Deeper: is a fork a full copy of the entire history?

Yes — a fork starts as a complete copy of the repository, including every commit, branch, and tag that existed at the moment you forked it. It's not a shallow snapshot. What it does not automatically do is stay updated — a fork is frozen at the moment you created it until you deliberately sync it with upstream, which is exactly why forks can drift out of date if you don't sync regularly.

Quick recap
  • Clone when you already have (or will get) write access; fork when you don't and won't.
  • A fork is created on GitHub, under your account, with full history — then cloned locally like any repo.
  • Sync a fork by adding the original as upstream, fetching and merging from it, then pushing the result to your fork (origin).
Sub-topic 3 of 6

3. Pull requests

At a glance
  • A pull request (PR) is a GitHub-hosted request to merge one branch into another — it's not a git object at all, it's a GitHub feature layered on top of git branches you've already pushed.
  • The workflow: branch, commit, push the branch, open a PR on GitHub, get it reviewed, address feedback, merge.
  • A draft PR is the same thing marked "not ready yet" — visible for early feedback, but blocked from merging until marked ready.
Why this matters: the pull request, not the commit, is the actual unit of collaboration on GitHub — it's where review happens, where discussion is recorded, and where a change is either approved or sent back for more work.
What is... a pull request? A pull request proposes merging one branch (yours, with new commits) into another (usually main). It's created and lives entirely on GitHub — opening one doesn't touch your local repository at all, it just tells GitHub "here's a branch I've pushed; please compare it against the target branch and let people review the difference before it's merged."

Everything up through "push the branch" is exactly what Chapter 28 already taught, aimed at a remote instead of staying purely local:

terminal
git checkout -b add-shopping-list
# ... make changes, commit as usual (Chapter 28) ...
git push -u origin add-shopping-list
actual output of pushing a new branch for the first time
To ../upstream-remote.git
 * [new branch]      add-shopping-list -> add-shopping-list
branch 'add-shopping-list' set up to track 'origin/add-shopping-list'.

That push is the last purely-local step. From here, opening the actual pull request happens on github.com — GitHub detects the freshly-pushed branch and offers a "Compare & pull request" button. Since that page can't be honestly screenshotted in this environment, here's what it looks like, described as a plain-text mockup:

Illustrative text mockup โ€” not a real screenshot

This represents GitHub's actual "Open a pull request" form, described in prose/structure since it can't be captured as a real screenshot here.

base: main  <-  compare: add-shopping-list

  Title:  Add shopping list feature

  Description (markdown, supports checklists and issue links):
  +----------------------------------------------------------+
  | ## What this does                                        |
  | Adds a `ShoppingList` class with add/remove/total methods.|
  |                                                            |
  | ## Why                                                    |
  | Closes #42                                                |
  |                                                            |
  | ## How to test                                            |
  | Run `python3 shopping_list.py` and try adding 3 items.    |
  |                                                            |
  | - [x] Added tests                                         |
  | - [ ] Updated README                                      |
  +----------------------------------------------------------+

  Reviewers: [ + Request review ]     Labels: [ enhancement ]

  [ Create pull request ]   [ Create draft pull request ]

A good PR description does three things, and the mockup above is deliberately structured around them:

Thought process: a PR description is written for a reviewer who has zero context on what you were thinking -- the goal isn't to describe every line changed (the diff already shows that), it's to answer "why does this exist" and "how do I check it actually works" without them having to ask.

Write the prompt you'd give an AI assistant to help with this PR:

Show a strong version of this prompt
Write a GitHub pull request description in markdown for a branch called add-shopping-list being merged into main. It adds a ShoppingList class with add/remove/total methods, and it should close issue #42. Structure it with three sections: "## What this does" (plain summary, not a diff recap), "## Why" (motivation, with "Closes #42" so GitHub auto-links and closes the issue on merge), and "## How to test" (exact runnable steps a reviewer can follow, e.g. "Run python3 shopping_list.py and try adding 3 items"). Add a markdown checklist at the end with "Added tests" checked and "Updated README" unchecked.
What is... a draft pull request? A draft PR is a normal pull request marked as not-yet-ready-to-merge. It still shows the diff, still allows comments, and still runs any automated checks — but GitHub blocks the merge button and doesn't request reviews automatically. It's the right choice for "I want early feedback on direction before I polish this" or "I'm intentionally leaving this open overnight and don't want a reviewer to think it's finished." A single click ("Ready for review") converts it to a normal PR with no new commits needed.

After a PR is open, the workflow loops between review and revision, entirely by pushing more commits to the same branch — a PR isn't a snapshot, it's a live view of whatever the branch currently contains:

the PR loop
open PR  -->  reviewer comments  -->  you push new commits
    ^                                          |
    |                                          v
    +---------  PR updates automatically  <----+
                (same branch, no new PR needed)

  ... repeat until approved ...  -->  merge  -->  branch usually deleted
Go Deeper: does a pull request require a fork?

No — PRs work the same way whether the branch lives on a fork or directly on the same repository. Team members with direct push access typically branch straight on the shared repo (git checkout -b feature-x, push, open PR); outside contributors without push access fork first, since that's the only way they get somewhere to push a branch to at all. The PR mechanism itself doesn't care which situation you're in.

Quick recap
  • Branch, commit, push the branch, then open the PR on GitHub — opening a PR is a GitHub action, not a git command.
  • A good description states what changed, why, and how to verify it, often linking an issue with "Closes #N."
  • A draft PR is visible for early feedback but blocked from merging; pushing more commits updates the same PR in place.
Sub-topic 4 of 6

4. Code review

At a glance
  • A reviewer is checking for correctness, readability, test coverage, and whether the change fits the project's existing conventions — not just "does it run."
  • GitHub's three review outcomes are Comment (feedback, no verdict), Approve (good to merge), and Request changes (blocks merging until addressed).
  • Feedback should target the code, phrased as a question or suggestion where possible — and receiving it well means treating it as information about the code, not a judgment of the person.
Why this matters: code review is where most real bugs actually get caught before production — and it's also one of the most common places collaboration quietly breaks down, when feedback lands as personal criticism instead of a shared effort to improve the code.
What is... code review? Code review is the practice of one or more other people reading a proposed change before it merges — on GitHub, this happens directly on the pull request, as line-by-line comments attached to specific parts of the diff, plus an overall verdict (comment, approve, or request changes).

What an experienced reviewer is actually scanning for, roughly in the order they'd notice it:

Illustrative text mockup โ€” not a real screenshot

A stand-in for GitHub's real line-comment UI on a PR's "Files changed" tab.

Files changed  |  shopping_list.py

   14  def add_item(self, name, price=[]):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
       ๐Ÿ’ฌ Reviewer comment:
       Careful -- mutable default argument (Chapter 25's gotcha).
       Every call without an explicit `price` list will share the
       same one. Suggest `price=None` and building a fresh list
       inside the function if it's None.

       [ Reply ]  [ Resolve conversation ]

  Review summary:  ( ) Comment   ( ) Approve   (โ€ข) Request changes
  [ Submit review ]

Notice the shape of that comment: it names the specific problem, explains why it's a problem (not just "this is wrong"), and suggests a concrete fix — that's the difference between feedback someone can act on immediately and feedback that just creates friction. The same principle applies to receiving review:

Thought process: the useful AI-assist here isn't "review my code for me" in a vague sense -- it's asking for a specific, actionable pass (e.g. "check this function against the mutable-default-argument pattern") so the output is something a real human reviewer could also have written, not a generic "looks good" that teaches nothing.

Write the prompt you'd give an AI assistant to help review this PR:

Show a strong version of this prompt
Review this Python method as if you were leaving a code review comment on a GitHub pull request:

def add_item(self, name, price=[]):
    self.items.append((name, price))
    return self.items

Specifically check for: (1) the mutable default argument gotcha, (2) whether the parameter and variable names are clear, (3) whether this needs a docstring given it's a public method on a class other contributors will use. Write your feedback the way a helpful teammate would -- name the specific issue, explain briefly why it matters, and suggest a concrete fix -- not just "this is wrong."
What is... "Request changes" vs. "Approve"? Both are formal review verdicts attached to a PR, distinct from a plain comment. Approve signals the PR is good to merge as-is. Request changes is a blocking verdict — many repositories configure branch protection so a PR with unresolved "Request changes" literally cannot be merged until that same reviewer (or another) approves it. A plain Comment leaves feedback without blocking or approving anything.
Go Deeper: can a reviewer approve their own PR?

No — GitHub doesn't allow a PR author to approve their own pull request, precisely because review is meant to be a second set of eyes. On a solo-maintained repository (like this course's own, per its CONTRIBUTING.md) that means formal review often doesn't apply at all; the practice still matters for any team project, which is why it's taught here regardless.

Quick recap
  • Reviewers look for correctness, tests, readability, consistency, and focused scope — not just "does it technically run."
  • Comment, Approve, and Request changes are the three verdicts; only Request changes blocks a merge.
  • Give feedback that names the issue and suggests a fix; receive it as information about the code, not a judgment of the author.
Sub-topic 5 of 6

5. Issues & project workflow

At a glance
  • An issue is a tracked unit of work or a reported problem — a bug report, a feature request, a question, or a task — living on GitHub, separate from any specific branch or PR.
  • Labels categorize issues (bug, enhancement, good first issue); milestones group issues toward a shared deadline or release.
  • A PR description containing Closes #42, Fixes #42, or Resolves #42 links the two and auto-closes the issue the moment that PR is merged.
Why this matters: issues are how a project's actual to-do list stays visible to everyone — without them, "what needs doing" and "who's doing it" live only in people's heads or scattered chat messages, which doesn't scale past a handful of contributors.
What is... an issue? An issue is a standalone, trackable item on GitHub — a title, a description, comments, labels, and a status (open/closed). It's not code and it's not a branch; it exists purely to record "here's something that needs attention," and it can be referenced from commits, PRs, and other issues by number (#42).

A genuinely useful issue answers the questions a contributor would otherwise have to ask before they could even start:

Illustrative text mockup โ€” not a real screenshot

A stand-in for GitHub's real "New issue" form and issue page, described in prose/structure rather than captured as a screenshot.

Issues > New issue

  Title: ShoppingList.total() crashes on an empty list

  ## What's happening
  Calling .total() on a ShoppingList with zero items raises
  ZeroDivisionError instead of returning 0.

  ## Steps to reproduce
  1. cart = ShoppingList()
  2. cart.total()

  ## Expected
  Returns 0 for an empty list.

  ## Actual
  Traceback (most recent call last):
    ZeroDivisionError: division by zero

  ## Environment
  Python 3.12, macOS

  Labels: [ bug ]  Milestone: [ v1.1 ]  Assignees: [ ]

  ---
  Issue #42 opened 2 days ago  ยท  1 comment

  Linked pull requests
  #57  Add shopping list feature โ€” will Close this issue on merge

Thought process: a bug report is only as useful as its reproduction steps -- an AI assistant is genuinely good at turning a vague "it's broken" observation into the structured what/steps/expected/actual shape a maintainer can act on immediately, so this is a legitimately strong real-world use of AI assistance, not just a novelty.

Write the prompt you'd give an AI assistant to help write this issue:

Show a strong version of this prompt
I found a bug: calling .total() on an empty ShoppingList raises ZeroDivisionError instead of returning 0. Write this up as a well-structured GitHub issue in markdown with four sections: "## What's happening" (a one-sentence plain description), "## Steps to reproduce" (a numbered list of the exact minimal steps: create an empty ShoppingList, call .total()), "## Expected" (should return 0), and "## Actual" (paste the ZeroDivisionError traceback). Suggest one label ("bug") that fits.
What are... labels and milestones? A label is a small colored tag on an issue or PR (bug, enhancement, documentation, good first issue) used to filter and categorize at a glance. A milestone groups a set of issues/PRs under a shared target, usually a release or deadline (v1.1), and shows progress as a fraction (e.g. "6 of 10 closed"). Neither changes any code — both exist purely to keep a growing list of work organized and searchable.

The Closes #42 convention from Sub-topic 3 is the piece that actually connects issues to the PR workflow: GitHub scans every PR description and commit message for that phrase (case-insensitive, several verbs work: close, closes, closed, fix, fixes, fixed, resolve, resolves, resolved, followed by # and the issue number) and, the moment that PR merges into the repository's default branch, closes the referenced issue automatically — no separate step required.

Go Deeper: do issues have to be bugs?

No — issues are used for feature requests, questions, documentation gaps, and general discussion just as often as bugs. Many open-source projects use a good first issue label specifically to mark small, well-scoped tasks meant to help new contributors find a manageable place to start, which is exactly the kind of coordination issues exist to provide.

Quick recap
  • An issue is a trackable unit of work/problem, independent of any branch or PR.
  • A strong issue states the problem, repro steps, and expected vs. actual behavior.
  • Labels categorize, milestones group by deadline, and Closes #N links a PR to an issue and auto-closes it on merge.
Sub-topic 6 of 6

6. A real-world collaboration workflow

At a glance
  • Every piece from Sub-topics 1–5 exists to support one end-to-end loop: someone reports a problem, someone else fixes it, and the fix gets reviewed and merged — visibly, with a full paper trail.
  • This sub-topic walks that loop start to finish, using nothing beyond what's already been taught.
Why this matters: none of remotes, forks, PRs, review, or issues is interesting in isolation — they're only the full story once you see how they chain together on a real piece of work, which is what actually happens on every active GitHub project, open-source or private.

Here's the scenario, followed end to end. A user of an open-source project notices ShoppingList.total() crashes on an empty list.

the full loop, start to finish
1. USER files an issue
   -> Issue #42: "ShoppingList.total() crashes on an empty list"
      (problem, repro steps, expected vs. actual -- Sub-topic 5)

2. CONTRIBUTOR (no push access) forks the repo on GitHub
   -> clones their fork locally (Sub-topic 2)
   -> git remote add upstream 

3. CONTRIBUTOR branches and fixes it
   -> git checkout -b fix-empty-cart-total
   -> edits total() to return 0 for an empty list
   -> git add . && git commit -m "Fix total() on empty ShoppingList"
   -> git push -u origin fix-empty-cart-total   (pushes to THEIR fork)

4. CONTRIBUTOR opens a PR
   -> base: original repo's main  <-  compare: their fork's branch
   -> description includes "Closes #42"          (Sub-topic 3)

5. MAINTAINER reviews
   -> line comment: suggests also testing total() with negative
      prices, not just the empty-list case
   -> verdict: Request changes                    (Sub-topic 4)

6. CONTRIBUTOR addresses it
   -> adds the requested test
   -> git commit -m "Add test for negative price edge case"
   -> git push origin fix-empty-cart-total         (same branch -- PR updates automatically)

7. MAINTAINER re-reviews, approves, merges
   -> PR merges into main
   -> Issue #42 closes automatically (Closes #42, Sub-topic 5)
   -> fix-empty-cart-total branch is deleted (its history lives on in main)

8. CONTRIBUTOR syncs their fork
   -> git fetch upstream
   -> git merge upstream/main
   -> git push origin main                         (Sub-topic 2)

Every command in that walkthrough was verified for real earlier in this chapter — step 2's remote setup, step 3's branch-and-push, step 6's "push more commits to update the same PR," and step 8's fork sync are exact repeats of the commands already run against the bare-repo stand-in for GitHub, just placed into their real order of use. Nothing in this scenario needed a new git command — it needed knowing when to reach for each one, and that GitHub is the layer recording who reviewed what and why.

Thought process: the useful AI-assist across a whole workflow like this isn't one prompt -- it's knowing which step benefits from help (drafting the issue, drafting the PR description, reviewing the diff before requesting human review) and which steps are just running the right git command, which no assistant should be doing on your behalf without you understanding why.

Write the prompt you'd give an AI assistant for one part of this workflow โ€” drafting the fix's commit message and PR description together:

Show a strong version of this prompt
I fixed a bug where ShoppingList.total() raised ZeroDivisionError on an empty list instead of returning 0; the fix also adds a test for a negative-price edge case a reviewer requested. Write (1) a concise commit message in the imperative mood ("Fix ...", not "Fixed ..."), following the same convention as Chapter 28's commit messages, and (2) a PR description in markdown with "## What this does", "## Why" (including "Closes #42"), and "## How to test" sections, matching the structure this chapter's lesson used for its own PR description example.

One more thing this scenario makes concrete: nothing about it required the contributor to have any special access to the original project. Fork, PR, and review are specifically the mechanism that lets someone with zero write access still get a real fix merged — which is exactly how the overwhelming majority of open-source contributions happen.

Go Deeper: what if the maintainer wants to make a small tweak themselves, right on the contributor's PR?

GitHub supports this directly — a PR from a fork can allow the base repository's maintainers to push commits straight to the contributor's branch (a checkbox on the PR, on by default for most personal-fork PRs), or a maintainer can suggest an exact line change inline that the contributor accepts with one click. Either way, it's still the same branch, still the same PR — just an extra commit added to the loop already shown above.

Quick recap
  • Issue → fork/branch → push → PR (linked to the issue) → review → revise → merge → issue auto-closes → fork sync is the complete real-world loop.
  • Every command used is one this chapter already ran and verified — the workflow is about sequencing known tools, not new git syntax.
  • This exact mechanism is how contributors without write access get real changes merged into any project.
In the Real World

Points to Remember

← All Chapters Take the Quiz →