The gh pr command handles the complete pull request lifecycle — from creation through review to merge.
Creating a Pull Request
# Interactive — prompts for title, body, base branch, reviewers
gh pr create
# Non-interactive
gh pr create --title "Add login feature" --body "Implements OAuth login"
# Target a specific base branch
gh pr create --base develop
# Draft PR
gh pr create --draft --title "WIP: new feature"
# With metadata
gh pr create \
--title "Fix bug #42" \
--body "Closes #42" \
--reviewer octocat,coworker \
--assignee @me \
--label bugfix \
--milestone v2.0 \
--project "Sprint Board"Cross-Fork PRs
When working from a fork, gh pr create automatically detects the upstream repository and prompts you to choose:
- Base repository — where the PR targets (the upstream)
- Head repository — where to push your branch (your fork)
# From inside your fork
gh pr create --repo upstream-owner/repoListing Pull Requests
# Default: 30 open PRs
gh pr list
# Filter by state
gh pr list --state closed
gh pr list --state merged
gh pr list --state all
# Filter by labels, author, assignee, base branch
gh pr list --label bugfix
gh pr list --author @me
gh pr list --assignee octocat
gh pr list --base main
# Search
gh pr list --search "login"
# Limit results
gh pr list --limit 100
# JSON output
gh pr list --json number,title,author --jq '.[] | "\(.number) \(.title)"'Viewing a Pull Request
# View in the terminal
gh pr view 123
# Open in the browser
gh pr view 123 --web
# View the current branch's PR
gh pr view
# JSON output
gh pr view 123 --json title,body,reviews,mergeableChecking Out a Pull Request
Download and switch to a PR's branch locally:
gh pr checkout 123
# Checkout and create a custom local branch name
gh pr checkout 123 --branch my-local-name
# Checkout by branch name
gh pr checkout feature-branch
# Force (overwrite existing local branch)
gh pr checkout 123 --forceViewing the Diff
gh pr diff 123
# Diff with color
gh pr diff 123 --color alwaysReviewing a Pull Request
# Interactive review (opens editor for comments)
gh pr review 123
# Approve
gh pr review 123 --approve
# Request changes
gh pr review 123 --request-changes --body "Please fix the typo on line 42"
# Comment (without approving or requesting changes)
gh pr review 123 --comment --body "Looks good, minor suggestion..."Commenting
# Open editor
gh pr comment 123
# Inline
gh pr comment 123 --body "Great work!"
# Comment in the browser
gh pr comment 123 --webChecking CI Status
# See all status checks for a PR
gh pr checks 123
# Watch checks and wait for completion
gh pr checks 123 --watch
# Fail the command if any check fails (useful in scripts)
gh pr checks 123 --fail-fastMerging a Pull Request
# Interactive (prompts for merge method)
gh pr merge 123
# Specific merge method
gh pr merge 123 --merge # Merge commit
gh pr merge 123 --squash # Squash and merge
gh pr merge 123 --rebase # Rebase and merge
# Delete the branch after merge
gh pr merge 123 --delete-branch
# Auto-merge (merge automatically once checks pass)
gh pr merge 123 --auto --squash
# Disable auto-merge
gh pr merge 123 --disable-autoClosing and Reopening
gh pr close 123
gh pr close 123 --comment "Closing — no longer needed" --delete-branch
gh pr reopen 123Editing a Pull Request
gh pr edit 123 --title "Updated title"
gh pr edit 123 --body "Updated description"
gh pr edit 123 --add-label enhancement --remove-label bug
gh pr edit 123 --add-reviewer octocat
gh pr edit 123 --base develop
gh pr edit 123 --milestone v2.0Marking Ready for Review
Convert a draft PR to ready:
gh pr ready 123Convert back to draft:
gh pr ready 123 --undoReverting a Pull Request
Create a new PR that reverts the changes from a merged PR:
gh pr revert 123
# With custom title and body
gh pr revert 123 --title "Revert: login changes" --body "Reverting due to regression"
# Create the revert as a draft
gh pr revert 123 --draftUpdating the Branch
Update a PR branch with the latest changes from the base branch:
# Default: merge base branch into PR branch
gh pr update-branch 123
# Use rebase instead of merge
gh pr update-branch 123 --rebaseLocking and Unlocking
gh pr lock 123 --reason resolved
gh pr unlock 123Checking PR Status
See PRs relevant to you:
gh pr statusShows:
- PRs you created
- PRs requesting your review
- PRs for the current branch
A Full Workflow Example
# 1. Fork and clone
gh repo fork upstream-org/project --clone
cd project
# 2. Create a feature branch
git checkout -b fix-typo
# 3. Make changes and commit
echo "fixed" > file.txt
git add . && git commit -m "Fix typo in docs"
# 4. Create the PR (pushes the branch and opens the PR)
gh pr create --title "Fix typo in docs" --body "Fixes #42"
# 5. Watch CI checks
gh pr checks --watch
# 6. Merge when ready
gh pr merge --squash --delete-branchExercises
- Create a branch, make a commit, and open a PR:
gh pr create - List open PRs:
gh pr list - View your PR:
gh pr view - Check CI status:
gh pr checks - Merge it:
gh pr merge --squash --delete-branch