Lesson 06 · team collaboration · capstone

Remotes & Pull Requests

The last piece: how your local pointers talk to a server. Master one idea — a remote is just more pointers, living somewhere else — and pushing, PRs, and reading a shared graph all fall out of it.

You use push and pull by habit but have no model underneath. This lesson gives you that model, and with it the two final mission goals: open a clean pull request, and read git log --graph on a shared repo. Everything rests on one extension of the pointer idea from Lesson 02.

The one idea: a remote is a copy with its own pointers

origin is Git's default name for the server repo you cloned from (GitHub, GitLab, a colleague's machine). It's a full copy of the repo — same commits, its own branch pointers. Your local main and the server's main are two independent pointers that happen to share history.

To track the gap, Git keeps a third pointer locally: origin/main — a remote-tracking branch. Read it as: "where the server's main was the last time I synced." It's a cached bookmark, not live. It moves only when you fetch, pull, or push.

A ─ B ─ C origin/main ← server was here at last sync \\ D ─ E main HEAD ← your 2 local commits, not yet pushed

This graph says: you're 2 ahead of the server. git status literally prints "Your branch is ahead of 'origin/main' by 2 commits." Now it means something — it's comparing your main pointer to the origin/main cache.

fetch vs. pull — the distinction that removes surprises git fetch downloads the server's new commits and moves origin/main — but does not touch your main. It's the safe "show me what's new" with zero risk. git pull = fetch then merge origin/main into main — it downloads and merges in one step, which is where surprise merge commits and conflicts come from. When unsure on a shared repo, fetch first, look, then merge deliberately.

The pull-request workflow, end to end

A pull request (PR) is a GitHub/GitLab feature, not a Git command: "please review my branch and merge it into main." The Git half is just pushing a branch; the review half lives on the website.

1
Branch and build. git switch -c feature, commit your work — exactly Lesson 04. Never work directly on main on a team.
2
Push the branch, set upstream: git push -u origin feature. The -u (upstream) links your local feature to origin/feature once — after that, plain git push and git pull know where to go. GUI: "Publish Branch" in the Source Control panel.
3
Open the PR on the website: base main ← compare feature. Title + description explaining why. This starts the review.
4
Respond to review. Reviewer requests a change? Commit it on the same branch and git push. The PR updates automatically — no new PR needed. Repeat until approved.
5
Merge the PR with the website's button (a --no-ff merge commit by default — see Lesson 04), then delete the branch. Locally: git switch main, git pull to catch up.
"Clean reviewable history" — what the mission asked for A reviewer reads your commits, not just the final diff. Make it a story: each commit one logical change, a clear message, no "wip" / "fix typo" / "actually fix" noise. Two tools you already own from the solo half — commit --amend to fix the last commit before pushing, and git reset --soft to squash a few messy commits into one clean one before the PR. Both are history rewrites, so only on your unpushed branch — the reset-before-share rule still holds.

Reading the graph on a shared repo

The final mission goal. One command shows every pointer — local and remote — at once:

git log --graph --oneline --all --decorate
* f3a1c2 main Merge pull request #42 from feature |\\ | * 9d8e7f origin/feature address review: rename var | * 2b4c6a add feature |/ * 7a8b9c origin/main HEAD previous release

Read it bottom-up: history forked at 7a8b9c, two commits happened on feature (the second one addressing review), then f3a1c2 is the merge commit that rejoined them into main. The |\ and |/ are the fork and the rejoin — the exact three-way-merge shape from Lesson 04, now with remote pointers labelled. You can reconstruct what the team did without asking anyone. GUI: the Git Graph extension, or Source Control → "…" → View History, draws this same graph.

Your win — and the mission You can push a branch, open a PR with a history a reviewer will thank you for, fold in review feedback, and read a shared repo's graph cold. That's the last two mission goals. Both halves — never lose solo work, and collaborate without fear — are now covered end to end.

Go deeper

Primary source — read this one: Pro Git §3.5, "Remote Branches". The definitive treatment of origin/main, tracking branches, and fetch vs. pull, with Git's own pointer diagrams.

Then do it for real: GitHub Skills — guided courses that run inside a real GitHub repo, walking the full PR + review loop. The one resource in the workspace built specifically for this workflow.