You will open a pull request from the command line, run reviews, and merge only after checks pass. By the end you will have a review workflow and branch protection that keeps unreviewed code out of main.

Learning Objectives

  • Create and manage PRs with the gh CLI.
  • Request reviews and respond to feedback.
  • Require status checks and reviews before merge.
  • Time: ~2 hours · Difficulty: Intermediate · Prereqs: a GitHub repo and the gh CLI.

Architecture Overview

Environment Setup

You will need: the gh CLI authenticated (gh auth login) and a repo.

Before you begin: enable branch protection on main in repo settings.

Step-by-Step Execution

01
Open a pull request
gh pr create --base main --head feature/api --title "Add API" --body "Implements endpoint"
02
Review and check status
$ gh pr checks && gh pr review --approve
All checks were successful Approved pull request #42
03
Merge after checks pass
gh pr merge --squash --delete-branch

Progress So Far

Testing & Validation

gh pr list --state merged --limit 1 && git log main --oneline -1

You should see the merged PR and the squashed commit on main. With protection on, an unreviewed or failing PR cannot merge.

Troubleshooting
  • Merge button blocked: branch protection requires checks/reviews; satisfy them first.
  • gh not authenticated: run gh auth login and select the right account.
  • Stale branch after merge: use --delete-branch to keep the repo tidy.

Extension Ideas

  • Add automated checks in GitHub Actions.
  • Require CODEOWNERS review for sensitive paths.
  • Auto-merge once checks pass with gh pr merge --auto.

Key Results

  • Opened and merged a PR entirely from the CLI.
  • Enforced review approval before merge.
  • Required passing checks via branch protection.
  • Kept main clean with squash + branch deletion.