Track 05 · Lesson 6 of 7Working as a team with Git

Track 05 · Working as a team with Git

Reviewing others

Lesson 6 of 7· 6 min

Reviewing is half of working on a team. The best reviews run the code, not just read it, and that means jumping onto a teammate's branch and back without losing your own half-finished work.

The stash dance

Review PR #130 without losing your work

$ git statusOn branch feat/loginmodified:   src/pages/login.tsx

On branch

feat/login

Uncommitted work

login.tsx (on feat/login)

Stash

empty

  1. Your half-done work is parked (not yet)
  2. You’re on their branch to test it (not yet)
  3. Back on your branch (not yet)
  4. Your work is restored (not yet)

Goal: test PR #130, then get back to your own work with nothing lost.

Park, switch, return, restore#

Git won't switch branches when your uncommitted changes would be overwritten, and that's protecting you. git stash parks the changes, gh pr checkout gets their branch, git switch - returns to the branch you were on, and git stash pop brings your work back. Pop it on the wrong branch and your half-done work lands in their code, as the demo shows.

Approve, request changes or comment#

Approve when it works and reads well. Request changes when something must be fixed before merging, and say exactly what. Comment for questions and suggestions that don't block. Be specific and kind: "Login fails when the email has a + sign" helps; "doesn't work" doesn't.

A teammate asked me to review their PR#

When: You were tagged as a reviewer, or someone asked "can you test my PR?".

$ gh pr list --search "review-requested:@me"
1/12

All PRs waiting for your review.

Commands to copy

  • $ gh pr list --search "review-requested:@me"

    What needs my review?

  • $ gh pr checkout 130

    Run their code

  • $ gh pr review 130 --approve --body "Tested locally, LGTM"

    Approve

  • $ gh pr review 130 --request-changes --body "Login fails when the email has a + sign"

    Ask for a fix

  • $ git switch -

    Back to my branch

Check yourself

You ran git stash, checked out a teammate's PR, then ran git stash pop while still on their branch. What happened?