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.
No flags needed. gh asks you everything.
Commands to copy
$ gh pr createStep by step (asks questions)
$ gh pr create --fillTitle 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.
--base means "the branch my PR goes INTO".
Commands to copy
$ gh pr create --base developNormal feature work
$ gh pr create --base release/2.0A bug fix for an upcoming release
$ gh pr create --base mainProduction is broken: urgent hotfix
$ gh pr create --base feat/their-branchYour 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.
Type this and press Enter.
Commands to copy
$ gh pr edit 123 --base developChange where the PR goes
$ gh pr view 123 --webDouble-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.
Type this and press Enter.
Commands to copy
$ gh pr create --draft --base developOpen as a draft directly
$ gh pr ready 123Draft → ready for review
$ gh pr ready 123 --undoBack 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.
Start from the first branch, the one that is still in review.
Commands to copy
$ gh pr create --base feat/login-apiPR into the unmerged branch
$ gh pr edit 123 --base developPoint 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.
Type this and press Enter.
Commands to copy
$ gh pr edit 123 --add-reviewer alice,bob --add-label frontendOn a PR that already exists
$ gh pr edit 123 --add-assignee "@me"Assign yourself
$ gh pr create --base develop --reviewer alice,bob --label frontendAll in one go when creating
Check yourself