learn-github-for-builders-with-phoebe / Session 3 of 6
Learn GitHub for Builders with Phoebe · Session 3 of 6 · Tech track

Branching + PRs from the CLI

You can run the daily loop. Now do it the way real teams do: every change on its own short-lived branch, proposed as a pull request, reviewed, then merged - all without leaving the terminal. The PR is the same GitHub proposal object from the non-tech track; this session drives it with git switch and gh, and gives you the reviewer side done right.

🟡 Core Builders & analysts Terminal or Codespaces 45 min live + self-study
0-3 · Welcome 3-18 · Concepts 18-40 · Build-along 40-45 · Q&A
Part 0

Why branch at all, when you could just push to main

Because a branch is a safe sandbox and a pull request is a checkpoint. Session 1 told you branches are cheap pointers; this session spends them freely. You will create a branch, push it, open a PR from the terminal, and review a teammate's PR both as commenter and approver. The payoff is trunk-based development: main stays always-deployable while all the messy work happens on short-lived branches that only merge once reviewed and green.

Live - presented in session Self-study - read after class ★ Build-along - type it in your terminal Running artifact: your my-project repo, now branched + PR'd
★ What you walk out with today A feature branch created with git switch -c and pushed, your first pull request opened entirely from the terminal with gh pr create --fill, hands-on time on the reviewer side (gh pr review, comments, suggestions, approve), and a CODEOWNERS file that auto-requests the right reviewer for every path.
Part 1 · branch and switch

Branch and switch from the terminal 5 min live

The modern command for this is git switch - clearer than the old overloaded git checkout. One flag creates a branch and moves you onto it in a single step. Remember from Session 1: a branch is just a movable pointer, so making one is instant and costs nothing.

switch -c makes the pointer and moves HEAD onto it - instantly. C1 a3f9 C2 7b21 C3 c8de feature/add-docs → main → push -u origin feature/add-docs main stays put and deployable; your work rides the feature pointer until the PR merges.
🔍 Click to zoom - a feature branch is a new pointer off main; HEAD rides it, push -u publishes it
Liveswitch -c, work, push -u - the branch loop3 min▶
  • git switch -c feature/add-docs creates the branch and moves HEAD onto it in one step. Everything you commit now lands on the feature branch, leaving main untouched.
  • Name branches so the intent is obvious. Conventions like feature/, fix/, docs/ prefixes group work and read well in git branch. feature/add-usage-docs beats my-changes.
  • git push -u origin feature/add-docs publishes the branch to GitHub and sets upstream, so later just git push. This is what makes a PR possible - GitHub needs the branch before it can open one.
  • Keep the branch current. While you work, main moves on. Freshen up with git pull origin main (a merge) or rebase onto it - Session 4 goes deep on the difference. For now: pull main in often so the eventual merge is small.
# create the branch and hop onto it git switch -c feature/add-usage-docs Switched to a new branch 'feature/add-usage-docs' # do the work, then snapshot it git add . && git commit -m "docs: add usage section to README" # publish the branch and set upstream (once) git push -u origin feature/add-usage-docs branch 'feature/add-usage-docs' set up to track 'origin/feature/add-usage-docs'
Self-studyswitch vs the old checkout2 min read▶

You will still see git checkout everywhere online. It works, but it does two unrelated jobs - switching branches and restoring files - which caused years of confusion. Modern git split it: git switch changes branches, git restore (Session 2) restores files. Use the new pair; recognize the old one in other people's docs.

GoalModernOld
New branch + move to itgit switch -c namegit checkout -b name
Move to existing branchgit switch namegit checkout name
Discard file changesgit restore filegit checkout -- file
Part 2 · PRs without the browser

PRs without leaving the terminal (gh) 5 min live

The pull request is still the GitHub proposal object you met in the non-tech track: "here is my branch, please review and merge it." What changes here is you never touch the browser. gh opens it, fills it, and tracks it from where you already are - the terminal.

# open a PR, auto-filling title + body from your commits gh pr create --fill Creating pull request for feature/add-usage-docs into main https://github.com/phoebefu6/my-project/pull/7 # jump to it in the browser when you want the full UI gh pr view --web # see where every PR you touch stands - yours and ones needing review gh pr status
Livecreate, view, status, draft, link3 min▶
  • gh pr create --fill opens the PR and uses your branch's commits for the title and body - zero typing for a well-committed branch. Add --title / --body to override, or drop --fill for an interactive prompt.
  • gh pr view --web pops the PR open in the browser when you want the diff view or the checks tab. gh pr status shows a dashboard: your open PRs, and ones assigned to you for review.
  • Draft PRs for work in progress. gh pr create --draft opens it as a draft - CI runs, teammates can peek, but it is clearly "not ready to merge". Mark it ready with gh pr ready.
  • Link issues from the body. Put Closes #12 in the PR body and merging the PR auto-closes issue 12. It also cross-links them so the history explains itself.
Real world

How a working data team ships: nobody pushes to main. Every change - a new dbt model, a fixed query, a docs tweak - is a short-lived branch that lives a day or two, gets a PR, gets one review, and merges. main is always green and always deployable. That is trunk-based development, and it is why the team can release on any afternoon without a "code freeze" or a scary big-bang merge.

Self-studyMerge strategies: squash, merge commit, rebase2 min read▶

When a PR is approved, gh pr merge offers three shapes. The choice is a team convention, not a right answer - pick one and be consistent.

FlagWhat lands on mainGood when
--squashall branch commits collapse into one clean committhe branch had messy WIP commits; you want a tidy main history
--mergeevery branch commit plus a merge commit with two parentsyou want the full detailed history preserved
--rebasebranch commits replayed onto main, no merge commityou want a linear history without merge commits

Most modern teams default to squash for a clean, one-commit-per-PR main. Session 4 covers the rebase mechanics behind that third option.

Part 3 · the reviewer side

Review deep half: the reviewer side done right 5 min live

In the non-tech track you saw a PR get reviewed. Now you are the reviewer, from the terminal. Reviewing well is a craft: you approve, request changes, or comment; you can propose exact code with a suggestion the author accepts in one click; and CODEOWNERS makes sure the right person is asked automatically. Good review is where quality and mentorship both happen.

Open the PR, CI runs, reviewer weighs in, author addresses, then merge. open PR CI runs reviewer: comment / suggest author addresses it approve → merge loop until green + happy CODEOWNERS: /pipelines/ @data-team auto-requests the right reviewer per path on open
🔍 Click to zoom - the review loop, with CODEOWNERS auto-assigning the reviewer the moment the PR opens
LiveApprove, request changes, suggest, and CODEOWNERS3 min▶
  • Three verdicts. gh pr review --approve greenlights it, --request-changes blocks the merge until addressed, --comment leaves feedback without a verdict. Add -b "..." for the message.
  • Line suggestions. On the PR diff a reviewer can propose exact replacement code in a suggestion block; the author accepts it with one click and it becomes a commit. It turns "you should rename this" into "here, I renamed it - click to take it".
  • CODEOWNERS auto-assigns reviewers. A .github/CODEOWNERS file maps paths to owners, so a PR touching /pipelines/ automatically requests the data team. No more "who should review this?" - GitHub knows.
  • What good review comments look like. Specific, kind, actionable. "This loop re-reads the file each iteration - can we read once above?" beats "this is slow". Praise what is good; the PR is a conversation, not a gate.
# check out a teammate's PR to read it locally gh pr checkout 7 # leave a single comment without a verdict gh pr review 7 --comment -b "Nice - one nit on the loop, see thread" # or approve it outright gh pr review 7 --approve ✓ Approved pull request #7
Self-studyTrunk-based vs git-flow-lite, and branch naming2 min read▶

Two common workflows, and when each fits:

WorkflowShapeFits
Trunk-basedshort-lived branches off main, merged in a day or two; main always deployablemost modern teams, continuous delivery, small frequent changes
Git-flow-litea longer-lived develop branch plus release branchesscheduled releases, versioned products shipping to customers

Default to trunk-based with short branches unless you have a real reason not to - long-lived branches drift from main and turn merging into archaeology. Branch naming taxonomy that reads well: feature/<short-desc>, fix/<short-desc>, docs/<short-desc>, chore/<short-desc>. Keep it lowercase, hyphenated, and about the intent.

Build-along 1 of 3

Your first branch + PR from the CLI ★ 7 min · everyone branches

In your my-project repo: git switch -c feature/add-usage-docs. Confirm you moved with git status - it names the new branch.

Edit the README (add a short "Usage" section), then git add . and git commit -m "docs: add usage section to README".

Publish the branch: git push -u origin HEAD. (HEAD is a handy shorthand for "the branch I am on" so you do not retype the name.)

Open the PR from the terminal: gh pr create --fill. Then gh pr view --web to see your proposal live on GitHub - branch, diff, and all.

Build-along 2 of 3

Build the history you are about to make ★ 8 min · everyone clicks

Before you merge your real PR, rehearse the exact shape here. Reproduce Build-along 1 as a graph: a commit on main, a feature branch, two commits on it, back to main, then merge. What you build in the widget is the history your PR is about to create for real.

Reproduce the branch-commit-merge shape: commit on main, make a feature branch, commit twice on it, switch back to main, merge.

Note the merge commit with two parents - that is exactly what clicking Merge on your PR (with --merge) will create. Squash would collapse the two feature commits into one instead.

Build-along 3 of 3

Pair review via gh ★ 6 min · review both sides

Pair up. Partner A already has a PR open (from Build-along 1). Partner B: gh pr checkout <number> to pull A's branch down and read the diff locally.

Partner B leaves one comment: gh pr review <number> --comment -b "one specific, kind, actionable note". Make it real - a genuine observation about the change.

Partner B approves: gh pr review <number> --approve. Partner A watches the approval land in gh pr status.

Partner A merges: gh pr merge --squash. Both run git switch main && git pull to sync. You just did a full review cycle without opening the browser.

Solo? Review yourself No partner? Open the PR, read your own diff with gh pr diff, and merge it. Reading your change as a reviewer catches surprisingly many of your own bugs - do it every time.
After the session

This week ◐ 25 min total

Check yourself

Three questions before you go 🎯 ◐ 90 seconds

1 · What does git switch -c feature-x do?

The -c flag means create. switch -c makes the new pointer and moves you onto it at once - since a branch is just a pointer (Session 1), this is instant and copies nothing.

2 · What does gh pr create make?

A PR is the GitHub proposal object: "here is my branch, please review and merge it." gh pr create opens it from the terminal; --fill borrows the title and body from your commits.

3 · What is the CODEOWNERS file for?

CODEOWNERS lives at .github/CODEOWNERS and maps paths to people or teams. When a PR changes a matching path, GitHub automatically requests that owner's review - so the right eyes see the right changes.

Source material

Official GitHub Skills coverage

This session drives the review-pull-requests Skills exercise from the CLI and covers its deep half - the reviewer side - alongside the branch and PR mechanics from Introduction to Git.

✓Review pull requests (skills/review-pull-requests) - deep halfgh pr review, comments, suggestions, request-changes, approve - Part 3 + Build-along 3
✓Introduction to Git - branch / switch / pushgit switch -c, push -u, PR creation - Part 1-2 + Build-along 1
✓CODEOWNERS auto-reviewpath-to-owner mapping - Part 3 + homework
◐Merge strategies (squash / rebase / merge commit)self-study card; Session 4 covers the rebase mechanics
◐gh aliases and shortcutsmentioned; HEAD shorthand, gh pr status, gh pr ready

Session 3 cheat sheet · pin this

Branch loopgit switch -c feature/x → work → commit → git push -u origin HEAD.
Open a PRgh pr create --fill · gh pr view --web · gh pr status · gh pr create --draft.
Review a PRgh pr checkout N → read → gh pr review N --comment / --request-changes / --approve.
Merge itgh pr merge --squash (tidy) · --merge (full history) · --rebase (linear).
CODEOWNERS.github/CODEOWNERS maps paths to owners - auto-requests the right reviewer. Link issues with Closes #12.
WorkflowTrunk-based: short branches off main, main always deployable. Names: feature/, fix/, docs/.