CS210 · Block 3 · Lesson 25

Git in Depth II: Collaboration

Remotes · fetch, pull, push · The rejected push · Pull requests · Code review
At a glance: Lesson 24 was Git by yourself on one machine. Today is Git with a team. Your repository now lives in two places at once, and keeping them in sync is where collaboration gets interesting. You will run the full remote loop (including the rejected push that confuses every beginner), learn how pull requests propose changes, and practice giving the kind of code review comments that actually get bugs fixed. Two walkthroughs in Section 5 build the skills; the two labs apply them — you open a pull request in Lab 1 and review one in Lab 2.
Contents
  1. Lesson Objectives
  2. Assigned Readings
  3. Pre-Class Work
  4. Lesson Materials and Overview
  5. In-Class Work
  6. After Class
1. Lesson Objectives

By the end of this lesson, cadets will be able to:

  1. Synchronize a local repository with a remote using fetch, pull, and push. (Outcomes 6, 7)
  2. Submit and respond to pull requests in a collaborative workflow. (Outcome 6)
  3. Conduct constructive code reviews using established conventions. (Outcomes 6, 4)
2. Assigned Readings

Complete before class. These give you the vocabulary we will use in the walkthroughs and labs.

Source Sections Why
Beej-Git Ch. 9, 10, 14, 17 (Remotes: Repos in Other Places, Remote Tracking Branches, Collaboration across Branches, GitHub: Forking and Pull Requests) How remotes, push/pull, and pull requests actually work
Supplementary notes (instructor) Code review workflow and conventions What a good review comment looks like; severity and tone
Heads up: the Beej site may be blocked on the USAFA network. If the link does not load on a lab machine, read it on a personal device or through the course Resources mirror.
3. Pre-Class Work
Do this first
Plan on 20 to 30 minutes for the reading. The hands-on learning happens during the two in-class walkthroughs; come ready to type and to read code critically.

Pre-Class Checklist

1
Read Beej-Git Ch. 9, 10, 14, and 17 (Remotes: Repos in Other Places, Remote Tracking Branches, Collaboration across Branches, GitHub: Forking and Pull Requests)
Focus on these ideas; you do not need to memorize commands, just recognize the terms:
  • remote, origin, and remote-tracking branches (origin/main)
  • fetch vs pull vs push
  • what a pull request is and why teams use one
2
Refresh your Lesson 24 conflict-resolution skill
Today's git pull can produce a merge conflict, and you resolve it the exact same way you did in Lesson 24. If that feels rusty, skim your Lesson 24 notes so it is fresh.
3
Skim the In-Class section below
You will see two interactive walkthroughs: one for the remote sync loop, one for code review. No need to use them yet; just know they are there.
4. Lesson Materials and Overview

Lesson 24 gave you branching, merging, and conflict resolution on a single machine. Today the repository lives in more than one place, and the new skill is keeping those copies in agreement while a teammate is changing the same code. The reference material below covers the concepts you will see in lecture and practice in the two walkthroughs.

Jump to
Slides Two Places Sync Commands The Rejected Push Pull Requests Code Review

Slides

The Lesson 25 deck covers the local-versus-remote mental model, the four sync commands, the rejected push, pull requests, and what makes a good code review comment. The slides are the spine of the lecture; the two walkthroughs in Section 5 are where you practice.

Open Lesson 25 slides →

Your repo now lives in two places

When you clone a shared repo, you end up with three things that matter. There is your local main (the branch you actually work on), the remote main on GitHub (the shared truth your teammates pull from), and a third thing called origin/main.

origin/main is a remote-tracking branch: your local copy's memory of where the remote was the last time you talked to it. It is not a live feed. The remote can move forward (a teammate pushes) and your origin/main will not know until you clone, fetch, or pull. Almost every sync headache traces back to that snapshot being stale.

The four commands that move work

Command What it does
git clone <url> Copy a remote repo to your machine, once, at the start. Sets up origin automatically.
git fetch Download the remote's new commits but do not merge them yet. Updates origin/main. The cautious "let me look first" move.
git pull fetch then merge in one step. Brings remote work into your branch. Can produce a merge conflict.
git push Upload your local commits to the remote so others can get them.

If a pull reports a conflict, resolve it exactly the way you did in Lesson 24: open the file, fix the conflict markers, then add and commit. The skill carries over unchanged.

The rejected push (and why it is not a break)

This is the single most common collaboration error, and it is Git protecting you, not failing. It happens when a teammate pushes to the remote after your last sync, so the remote has a commit you do not. When you try to push, Git refuses:

! [rejected] main -> main (fetch first)
error: failed to push some refs to 'origin'
hint: Updates were rejected because the remote contains work
hint: that you do not have locally. Pull and integrate the
hint: remote changes before pushing again.

The fix is always the same: git pull to bring in the teammate's work (resolving any conflict), then git push again. Read the hint Git gives you; in this corner of Git the error messages tell you exactly what to do. You will make this rejection happen on purpose in the remote_sync walkthrough.

Pull requests: propose, do not just push

On a team you usually do not push straight to main. Instead you do your work on a feature branch, push the branch, and open a pull request: a request to merge your branch into main. The name is a little confusing because it has "pull" in it, but it is about getting your work merged in, not pulling work down.

A pull request is a conversation around a diff. The title says what changed, the description says why, and reviewers leave comments before anything merges. That review checkpoint is how a team catches problems before they reach the shared branch and everyone's copy. In Lab 1 you open a real pull request for a small Summit Log feature.

What makes a good code review comment

A useful review comment is three things at once: specific (it points at a line and names the actual issue), actionable (it says what to change or check, ideally with a suggested fix), and kind (it is about the code, not the author, and assumes good faith). Compare:

Weak: “this is wrong”
Strong: “The loop uses i <= n, but valid indices are 0..n-1, so this reads one past the end. Should it be i < n?”

Lead with correctness. A review that flags whitespace while missing a buffer overflow has failed at the one job that mattered. Style and personal preferences come after, and should be clearly marked non-blocking so the author knows what truly must change before merge.

Reviewing is a form of testing. Some bugs compile cleanly under -Wall -Werror and still do the wrong thing; the only tool that finds them by inspection is a careful human reading the code. Ask of every change: what is the worst input this could get, and what would it do? That question is what you will practice in the code_review walkthrough and apply for real in Lab 2.

5. In-Class Work

Four things to do in class. Use the checklist to track your progress.

  • Work through the remote_sync walkthrough below. Thirteen guided tasks: clone, commit, push, watch a teammate diverge the remote, hit the rejected push, then pull and re-push. About 15 minutes.
  • Work through the code_review walkthrough below. Ten review decisions on a Summit Log pull request, including finding a real out-of-bounds bug by reading. About 15 minutes.
  • Complete Lab 1: Open a Pull Request. Add the elevation_per_mile feature on a branch and open a pull request against your team's main. Half autograded, half checked on your PR.
  • Complete Lab 2: Review a Pull Request. Review the provided PR #7 on the Summit Log and write your review in REVIEW.md. You must catch at least one correctness bug, not just style.

remote_sync Walkthrough

Thirteen tasks across four sections. Type each git command at the prompt. The terminal shows what git did; the right pane shows how your local branch and origin/main line up. Watch the right pane when the teammate pushes and when your push gets rejected.

Before you begin

Enter your name. It will appear on the completion screen so you can include it in your screenshot for the Lesson 25 reflection.

CS210 Lesson 25 · remote_sync Walkthrough

A guided run through the remote collaboration loop: clone, commit, push, hit the rejected push when a teammate gets there first, pull to reconcile, then push for real. The terminal shows what git did; the right pane shows how your local branch and origin/main line up.
Task 0 of 13
Section 1: Get the shared repo
Current task
Loading...
Repository state
~/summit-log$
How this works: This is not a real shell and there is no real network. It is a teaching simulation of the git collaboration loop. The task card tells you what to type next; only the expected command advances the walkthrough so the repository state stays predictable. Mistype twice and the hint button pulses. The point is the pattern: who has which commits, and what each command does to close the gap.

code_review Walkthrough

Ten short diffs from a Summit Log pull request. For each, read the code and pick the strongest review comment. Choosing reveals why it is strong or weak; you must choose before you can advance. There is no score, the goal is to train your eye before Lab 2.

Before you begin

Enter your name. It will appear on the completion screen so you can include it in your screenshot for the Lesson 25 reflection.

CS210 Lesson 25 · code_review Walkthrough

You are reviewing a teammate's pull request on the Summit Log. Each step shows a diff and asks you to pick the strongest review comment. A strong comment is specific, actionable, and kind: it points at a line, says what is wrong or could be better, and suggests a direction. Watch for the one diff that hides a real correctness bug.
Step 0 of 10
Section 1: What makes a review comment useful
Current step
Loading...
How this works: Read the diff, then choose the review comment you would actually leave. Choosing locks the options and shows feedback explaining why that comment is strong or weak. You must choose before you can advance. There is no score; the goal is to train your eye for what a useful comment looks like, because in Lab 2 you will write your own on a real seeded pull request.
6. After Class
  • Finish both labs if you did not complete them in class. Both share the same due date; submit Lab 1 through GitHub Classroom and Gradescope, and push your REVIEW.md for Lab 2.
  • Finished both walkthroughs? Enter both completion codes in the Lesson 25 reflection on Blackboard and attach your screenshots.
  • The remote loop and the review habit you practiced today are exactly what the Team PEX will need. This was not a graded event, but it is groundwork for the project.
  • Stuck on a rejected push, a merge conflict, or anything else? The Git troubleshooting card is linked in the help note below.
Need help? Schedule EI with your instructor. Bring the exact command you ran and the exact output or error message, especially for a rejected push or a merge conflict, since those are usually fixed in under a minute once we see the message. The Git troubleshooting reference card covers the pull-then-push pattern and the most common conflict messages.