LinuxCommandLibrary

gh-pr

Create, view, and manage GitHub pull requests

TLDR

Create a pull request

$ gh pr [[new|create]]
copy

Check out a specific pull request locally
$ gh [[co|pr checkout]] [pr_number|url|branch]
copy

View the changes made in the pull request for the current branch
$ gh pr diff
copy

Approve the pull request for the current branch
$ gh pr review [[-a|--approve]]
copy

Merge the pull request associated with the current branch interactively
$ gh pr merge
copy

Edit a pull request interactively
$ gh pr edit
copy

Edit the base branch of a pull request
$ gh pr edit [[-B|--base]] [branch_name]
copy

Check the status of the current repository's pull requests
$ gh pr status
copy

SYNOPSIS

gh pr <command> [<args>...] [flags]

PARAMETERS

-R, --repo <HOST/>OWNER/REPO
    Select another repository using the [HOST/]OWNER/REPO format

-h, --help
    Show help for command

DESCRIPTION

gh pr is a subcommand of the GitHub CLI (gh), enabling seamless management of pull requests (PRs) from the Linux terminal. It supports workflows like creating PRs from local branches, viewing details, listing open PRs, merging with strategies like rebase or squash, applying reviews, and checking out remote PRs into git branches.

Designed for developers, it minimizes browser use by integrating with git. For example, gh pr create drafts a PR with title, body, base branch, and reviewers. Flags allow targeting specific repos via --repo.

Requires GitHub authentication (gh auth login) and git repository context. Handles draft PRs, labels, assignees, and milestones. Output formats include table, JSON via --jq on subcommands. Ideal for CI/CD, team collaboration, and power users. Supports GitHub Enterprise with --hostname (global flag). Regularly updated with GitHub features.

CAVEATS

Requires gh installed (<code>apt install gh</code> or similar), GitHub auth, and internet. Subcommand-specific flags/flags override globals; no offline mode.

COMMON SUBCOMMANDS

create: Create PR
view: View PR details
list: List PRs
merge: Merge PR
checkout: Checkout PR branch

QUICK EXAMPLE

gh pr create --title 'Fix bug' --body 'Details'
gh pr view 123 --web (opens in browser)

HISTORY

Part of GitHub CLI, first released Feb 2020 (v0.5.0) as open-source Rust tool by GitHub. gh pr evolved from early betas, adding subcommands like rebase-merge (v1.0+), review APIs (v2.0+). Now at v2.40+, mirrors web UI features.

SEE ALSO

gh(1), git(1), hub(1)

Copied to clipboard