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

Track 05 · Working as a team with Git

Opening a PR

Lesson 4 of 7· 9 min

A pull request asks the team to merge your branch into another one. Getting the "into" right, the --base, matters more than any other flag, because it decides which commits reviewers see and where your code ends up.

Where does this PR go?

Mismatch the two and watch the commit list

I branched from

The PR goes into (--base)

feat: add login page

you wants to merge 4 commits into main from feat/login

  • feat: add profile page (#118)not yours
  • chore: bump dependencies (#120)not yours
  • feat: add login pageyours
  • fix: handle empty emailyours

This would ship unreleased develop work to production. It’s gh’s default target, so pass --base develop.

Already opened it? Fix the target without a new PR: gh pr edit 123 --base develop

Branch from where you'll merge into#

A PR shows every commit your branch has that the target doesn't. If you branched from develop and target develop, that's exactly your work. Mix them up and the PR fills with other people's commits, or worse, ships unreleased work into production. The rule is short: create your branch from the same branch your PR targets.

Open a PR for my work#

When: You have committed your changes and want the team to review them.

$ gh pr create
1/7

No flags needed. gh asks you everything.

Commands to copy

  • $ gh pr create

    Step by step (asks questions)

  • $ gh pr create --fill

    Title and description taken from your commits

  • $ gh pr create --title "feat: add login page" --body "Closes #42"

    Everything in one line

My PR must go into the target branch, not main#

When: Your team merges features into develop, and main is only for production. By default gh targets the repo's default branch, usually main.

$ gh pr create --base develop
1/7

--base means "the branch my PR goes INTO".

Commands to copy

  • $ gh pr create --base develop

    Normal feature work

  • $ gh pr create --base release/2.0

    A bug fix for an upcoming release

  • $ gh pr create --base main

    Production is broken: urgent hotfix

  • $ gh pr create --base feat/their-branch

    Your work builds on a teammate's unmerged branch

Oops, I opened the PR against the wrong branch#

When: The PR says it wants to merge into main, but it should go into develop.

$ gh pr view 123
1/5

Type this and press Enter.

Commands to copy

  • $ gh pr edit 123 --base develop

    Change where the PR goes

  • $ gh pr view 123 --web

    Double-check on GitHub

My work isn't finished, but I want early feedback#

When: You want your lead to look at your approach before you finish.

$ gh pr create --base develop
1/8

Type this and press Enter.

Commands to copy

  • $ gh pr create --draft --base develop

    Open as a draft directly

  • $ gh pr ready 123

    Draft → ready for review

  • $ gh pr ready 123 --undo

    Back to draft

My new work depends on a PR that isn't merged yet#

When: Your PR for feat/login-api is waiting for review, and now you are building the next piece on top of it.

$ git switch feat/login-api
1/10

Start from the first branch, the one that is still in review.

Commands to copy

  • $ gh pr create --base feat/login-api

    PR into the unmerged branch

  • $ gh pr edit 123 --base develop

    Point it at develop after the first one merges

Add reviewers or labels to my PR#

When: You want specific teammates to review, or your team uses labels like frontend or bug.

$ gh pr create --base develop
1/9

Type this and press Enter.

Commands to copy

  • $ gh pr edit 123 --add-reviewer alice,bob --add-label frontend

    On a PR that already exists

  • $ gh pr edit 123 --add-assignee "@me"

    Assign yourself

  • $ gh pr create --base develop --reviewer alice,bob --label frontend

    All in one go when creating

Check yourself

You branched from develop but ran gh pr create without flags. Where does the PR go by default?