🐍 Python for Everyone

← Back to challenges

Chapter 29 Interview Prep 55 min read

Interview Questions: GitHub & Collaboration

Nearly every professional software job asks some version of these questions, because nearly every professional software job uses GitHub (or something structurally identical to it) every single day. This set covers remotes, fork vs. clone, fetch vs. pull, what actually happens when you open a pull request, what reviewers look for, the three GitHub merge options, keeping a fork in sync, writing a good PR description and a good issue, linking issues to PRs, draft PRs, why force-pushing a shared branch is risky, and git blame in review.

1 What's the actual difference between forking a repo and cloning it?

Cloning (git clone) makes a local copy of a repository on your own machine — it works on any repo you have read access to, and it doesn't create anything new on the server. Forking is a GitHub-specific action (there's no plain git fork command) that creates a brand-new, independent copy of the repository under your own GitHub account, server-side, before you ever clone anything. You fork when you don't have push access to the original repo and need your own copy to push changes to; you just clone directly when you already have push access (your own repos, or a team repo you're a collaborator on). In practice: fork someone else's repo, then clone your fork — you very rarely clone a repo you don't own directly and expect to be able to push to it.

Treating "fork" and "clone" as interchangeable, or saying a fork is "just a local copy" — a fork lives on GitHub's servers under your account, and only becomes a local copy once you clone it.

"If you already have push access to a repo, do you still need to fork it?" (No — collaborators with push access typically clone the repo directly and push feature branches to it, opening PRs branch-to-branch within the same repo. Forking is specifically for contributors who don't have write access to the original.)

2 What is a "remote," mechanically — not GitHub-specific, just Git?

A remote is nothing more than a named URL that your local repository knows about, stored in .git/config. git remote add upstream /some/path or git remote add upstream https://github.com/org/repo.git both do the identical thing mechanically — they register a name pointing at a location git can fetch from and push to. There's nothing GitHub-specific about a remote at all: it works exactly the same whether the URL points at github.com, a company's internal Git server, or (as this chapter's own project proves) a plain local folder created with git init --bare. "Origin" is just the conventional name git gives the remote you cloned from — it isn't special beyond that default.

Describing a remote as if it's inherently tied to GitHub's infrastructure, or not knowing that a repo can have more than one remote at once (e.g. origin for your fork and upstream for the original).

"How would you check what remotes a repo currently has, and where they point?" (git remote -v — lists every configured remote name alongside its fetch and push URLs.)

3 What's the actual difference between git fetch and git pull?

git fetch downloads new commits and branch references from a remote into your local repo's remote-tracking branches (e.g. upstream/main) — but it never touches your current working branch or your working directory files. It's purely "go get whatever's new, and let me look at it before deciding what to do." git pull is fetch immediately followed by a merge (or rebase, if configured) of the fetched branch into your current branch — it does touch your working directory. Verified directly: after git fetch upstream, git log --oneline on your own branch shows no change at all; only after a subsequent git merge upstream/main (what pull would have done automatically) does your branch's history actually update.

Saying they're basically the same thing, or not knowing that pull can trigger a merge conflict right there on the spot, while fetch never can (since it never merges anything).

"Why might an experienced developer deliberately prefer fetch-then-merge over a plain pull?" (Fetch first lets you inspect what actually changed — git log main..upstream/main or git diff main upstream/main — before merging it into your own branch, rather than merging blind and dealing with the consequences after the fact.)

4 What actually happens, mechanically, when you open a pull request on GitHub?

A pull request isn't a git object at all — it's a GitHub-specific wrapper around two things git already understands: a base branch (usually the target repo's main) and a head branch (your feature branch, often on your fork). Opening a PR tells GitHub "compare these two branches and let people discuss, review, and eventually merge the difference." Under the hood, GitHub fetches your branch into the target repo's internal ref namespace so it can be diffed and, eventually, merged — mechanically similar to what this chapter's own project does by hand with git fetch <fork-url> branch:local-ref-name. No commits are actually moved into the base repo's real branches until someone actually merges the PR.

Describing a PR as though it's a Git concept — it's a platform feature (GitHub, GitLab, Bitbucket each implement their own version) layered on top of ordinary branches and commits, not something git itself has any built-in notion of.

"Does pushing a new commit to your feature branch after opening a PR require opening a new PR?" (No — the PR is a live comparison, not a snapshot. Pushing more commits to the same branch automatically updates the existing open PR with the new diff.)

5 What does a good reviewer actually look for in a pull request?

Correctness first — does the change actually do what the PR description claims, and does it handle the edge cases a reviewer can think of on the spot. Then: does it fit the existing codebase's conventions and architecture rather than introducing a one-off pattern; is it covered by tests (new tests for new behavior, no regressions in existing ones); is the diff scoped to one logical change rather than mixing an unrelated refactor into the same PR (which makes it much harder to review or revert); and is anything risky — a schema change, a security-sensitive input, a breaking API change — called out explicitly rather than left for the reviewer to notice on their own.

Reducing review to "does it look like it works" without mentioning scope, tests, or conventions — real review is about maintainability and risk, not just whether the code runs once.

"What's a warning sign that a PR should be split into smaller ones before review?" (It touches many unrelated files/concerns at once, its description needs several paragraphs to explain "what changed," or it mixes a refactor with new behavior — all of these make it much harder to review carefully and much riskier to revert if something's wrong.)

6 What's the real difference between "Approve," "Request changes," and just leaving a "Comment" on a GitHub review?

All three let a reviewer leave feedback, but they carry different weight. "Comment" leaves feedback without taking a formal position — useful for questions or optional suggestions that shouldn't block anything. "Approve" is a formal sign-off that the PR is ready to merge as-is (possibly with only optional nitpicks) — on repos with branch protection rules requiring approval, this is what actually unlocks the merge button. "Request changes" is a formal block — it explicitly says "do not merge this yet," and on a protected branch it can prevent merging entirely until the same reviewer (or another required one) either resubmits an approval or the block is dismissed.

Treating all three as equivalent ways to "leave a note" — the distinction between blocking and non-blocking feedback is exactly the point of having three separate options instead of one comment box.

"If you found one real bug but the rest of the PR is solid, which would you pick?" (Request changes — a genuine bug is blocking by definition, even inside an otherwise good PR. Approve is only for "this is ready to merge," not "mostly ready.")

7 What's the actual difference between GitHub's three merge options — merge commit, squash-and-merge, and rebase-and-merge?

Merge commit (git merge --no-ff under the hood, exactly what this chapter's own project runs by hand) keeps every individual commit from the feature branch, plus adds one new merge commit tying the two histories together — the base branch's history shows the real, granular commit-by-commit story, with branch structure visible in git log --graph. Squash-and-merge collapses every commit on the feature branch into a single new commit on the base branch — clean, linear history, but the feature branch's individual commit-by-commit story is gone from main (still recoverable from the original branch/PR if it isn't deleted). Rebase-and-merge replays each individual commit from the feature branch directly onto the tip of the base branch, one at a time, with no merge commit at all — linear history like squash, but every original commit is preserved individually rather than collapsed into one.

Not knowing these are three genuinely different resulting histories, or claiming one is objectively "correct" — teams pick based on whether they value granular commit history (merge commit, rebase) or a clean one-commit-per-feature main branch (squash), not because one option is universally better.

"Which option would make the most sense for a feature branch with 15 messy 'wip' commits?" (Squash-and-merge — it turns 15 noisy work-in-progress commits into one clean, well-described commit on main, without needing to manually clean up the branch's history first.)

8 How do you actually keep your fork in sync with upstream once it starts falling behind?

Four real commands, verified directly in this chapter's own project: with upstream already added as a remote, git fetch upstream downloads upstream's latest commits into upstream/main without touching your own branches; git checkout main switches to your local main; git merge upstream/main brings those new commits into your local main (a clean fast-forward if you haven't made local commits directly on main, which is exactly why feature work belongs on its own branch, not on main); and finally git push origin main pushes the now-updated main back up to your fork on GitHub, so your fork's main matches upstream's again. Note this never touches upstream itself — you don't have (and don't need) push access to the original repo to sync your own fork.

Suggesting you'd re-fork the repo from scratch every time it falls behind, or not knowing that syncing requires the upstream remote to exist in the first place (GitHub doesn't add it automatically when you fork — you add it yourself after cloning).

"What happens if you'd made your own commits directly on your fork's local main before syncing?" (The merge won't be a clean fast-forward — you'd get a real merge commit combining upstream's new work with your own, which is exactly why the convention is to never commit directly to main and always work on a feature branch instead.)

9 What separates a good pull request description from a bad one?

A good PR description answers, up front, what a reviewer would otherwise have to reverse-engineer from the diff: what changed (a plain-language summary, not just "see diff"), why (the motivating bug or feature — link the issue if one exists), how to test it (concrete steps or commands a reviewer can actually run), and anything risky or non-obvious a reviewer should pay special attention to (a breaking change, a migration step, a deliberately-skipped edge case). A bad one either restates the diff in prose ("changed function X to do Y" with no why) or is so thin ("fix bug") that the reviewer has to fully reverse-engineer intent from the code alone.

Treating the PR title alone as sufficient, or writing a description that's purely a changelog of file names touched rather than explaining the reasoning and the risk.

"Why does 'how to test it' matter even when there are automated tests in CI?" (CI proves the tests that already exist still pass — it says nothing about whether a reviewer can independently confirm the actual described behavior works, especially for anything UI-facing or environment-dependent that automated tests may not fully cover.)

10 What makes a GitHub issue actually useful, versus one that just creates noise?

A useful issue is reproducible and specific: clear steps to reproduce the problem, what actually happened, what was expected instead, and enough environment detail (version, OS, relevant config) that someone who's never seen the bug can attempt to reproduce it without asking follow-up questions first. For a feature request, the useful version states the actual problem or use case being solved, not just a proposed solution — "I need X because Y" gives a maintainer room to suggest a better approach than the one originally imagined. A noisy issue is vague ("it's broken"), lacks repro steps, or bundles multiple unrelated problems into one thread.

Describing a good bug report as just "a clear title" — title clarity matters, but reproducibility is what actually lets someone act on it without a back-and-forth first.

"Why do maintainers often ask for a minimal reproduction rather than accepting a full production codebase link?" (A minimal repro strips away everything irrelevant to the bug, which both makes the actual cause much easier to isolate and avoids requiring the maintainer to understand an entire unrelated codebase just to help.)

11 How do you link an issue and a pull request together on GitHub, and what does a closing keyword actually do?

Writing a specific keyword followed by an issue number in a PR's description or in one of its commit messages — e.g. Fixes #12, Closes #12, or Resolves #12 — creates a real, tracked link between the PR and that issue in GitHub's UI (the issue shows "linked pull request," and the PR shows which issue it addresses). The functional effect: when a PR containing that keyword is merged into the repo's default branch, GitHub automatically closes the referenced issue for you — no manual step needed. A plain reference without one of those specific keywords (just typing #12 alone) still creates a visible cross-link between the two, but does not auto-close the issue on merge.

Assuming any mention of an issue number auto-closes it — only the specific recognized closing keywords trigger the auto-close behavior; a bare #12 just cross-links.

"Where can the closing keyword go — only the PR description, or also a commit message?" (Both — GitHub recognizes closing keywords in a PR's description and in individual commit messages within it. Either location triggers the auto-close once that PR is merged to the default branch.)

12 What is a draft pull request, and when would you actually open one?

A draft PR is a normal pull request marked explicitly as "not ready for review yet" — it still runs CI, still shows the diff, still lets people comment, but it signals to reviewers and to the "Merge" button itself that this isn't a finished, review-ready change (GitHub disables merging on a draft until it's explicitly marked "Ready for review"). It's the right tool when you want early, work-in-progress visibility — showing a team the direction of a large change before it's finished, getting CI feedback early, or asking for input on an approach mid-implementation — without implying "please formally review and approve this now."

Describing a draft PR as just a PR with "WIP" typed into the title — that's the old convention teams used before GitHub added real draft-PR support; a real draft PR is a distinct, first-class state that actually blocks the merge button, not just a naming convention.

"Does marking a PR as a draft change what commands git itself runs?" (No — draft status is purely a GitHub-side flag on the PR object, not a git concept. The underlying branch, commits, and push/fetch mechanics are completely identical to a normal PR.)

13 Why is force-pushing to a shared pull request branch genuinely risky, and when is it still reasonable to do?

A force-push (git push --force) rewrites a branch's history on the remote to match your local branch exactly, discarding whatever commits used to be there instead. On a branch only you work on, that's low-risk. On a PR branch other people have already reviewed, it's genuinely dangerous for two concrete reasons: it can silently orphan a reviewer's inline comments (GitHub anchors review comments to specific commits/lines — rewriting history can leave those comments detached from any code that still exists, effectively losing that review context), and it can discard commits a collaborator pushed to the same branch in the meantime, permanently, if they haven't been fetched elsewhere first. It's still reasonable to do deliberately — cleaning up a WIP branch's history before requesting review, or after a rebase onto an updated base — but the safer version is git push --force-with-lease, which refuses to overwrite the remote branch if it has commits your local copy hasn't seen, catching exactly the "someone else pushed since I last fetched" case before it causes damage.

Treating force-push as simply forbidden with no explanation, or not knowing --force-with-lease exists as the safer alternative — the real answer is about understanding the specific risk, not memorizing a blanket rule.

"Why does force-pushing specifically risk losing review comments, when the code itself isn't deleted?" (GitHub's inline review comments are tied to a specific commit SHA and line at the time they were written. If a force-push rewrites history so that commit no longer exists on the branch, GitHub can no longer show the comment anchored to live code the same way — the comment's context effectively becomes stale, even though the comment text itself still exists in the PR's history.)

14 How is git blame actually useful during code review, rather than just "who wrote this line"?

git blame <file> shows, line by line, which commit last touched each line and who authored it — but the real reviewer's use case is almost never "assign blame" in the accusatory sense. It's for recovering context a diff alone doesn't show: when a PR modifies a confusing or unusual-looking line, git blame (or, on GitHub, clicking "blame" on that file) traces back to the commit and its message that introduced it — often revealing it was a deliberate fix for a specific past bug, not an oversight. That context can be the difference between a reviewer correctly leaving it alone and a reviewer incorrectly "simplifying" it back into the same bug it was written to prevent.

Describing git blame only as a way to find out who to complain to about a line of code — missing that its actual value in review is historical context, specifically for understanding *why* something non-obvious was written the way it was.

"If git blame shows a suspicious line was 'introduced' by a large refactor commit, what's the next step?" (Use git log -p or GitHub's "View blame prior to this change" option to walk back past that refactor commit to the change before it — a big rewrite commit often isn't the line's real origin, just the most recent commit to move or reformat it.)

Rapid-Fire Review

Quick recall check — fill in each blank and hit Check.

🎉 Perfect score — you're ready to talk about this chapter in an interview.
← Challenges Build the Project →