Home / Alt manpages / gh-pr-view(1)

  • gh-pr-view(1)
  • User command
  • linux

Inspect a GitHub Pull Request with gh pr view

Use gh pr view to read a pull request from the terminal, as plain text, filtered JSON or a browser tab. The examples use GitHub CLI 2.87.3, installed on 23 September 2026. Allow about ten minutes if gh is already installed and authenticated.

  • You need: a shell, GitHub CLI, and access to the repository containing the pull request.
  • Read-only. This guide only reads pull request data or opens its web page. It never approves, merges, edits or closes anything, so no elevated privileges are needed.

1. Check the installed command

Confirm which executable will run and record its version. These are ordinary, read-only commands:

$ command -v gh
/usr/bin/gh
$ gh --version
gh version 2.87.3 (2026-02-23)
https://github.com/cli/cli/releases/tag/v2.87.3

Your path and release date can differ. The option names in this guide come from the installed version. If a later package prints a different field list, read the local help:

$ gh pr view --help
Display the title, body, and other information about a pull request.

Checkpoint

If command -v gh finds nothing, stop and install GitHub CLI through your normal package-management process. Do not work around a missing executable with an untrusted download.

2. View a pull request by number

Change to a local checkout of the repository, then give the pull request number. Replace the placeholders with the repository you intend to inspect:

$ cd /path/to/OWNER-REPO
$ gh pr view 123
Pull request title
opened by contributor. 2 comments. (label)

  Pull request body

View this pull request on GitHub: https://github.com/OWNER/REPO/pull/123

The URL, title, body and comment count depend on the real pull request. A number is resolved in the current repository, so check the prompt and working directory before copying a number from another project.

With no checkout available, select the repository explicitly with --repo or -R:

$ gh pr view 123 --repo OWNER/REPO

The repository form is [HOST/]OWNER/REPO, and the host prefix is useful for a GitHub Enterprise installation. A repository argument does not change your current directory or any Git branch.

3. Select by URL, branch or current branch

gh pr view accepts a pull request number, URL or branch name. A full URL is unambiguous when you are reviewing a link someone sent you:

$ gh pr view https://github.com/OWNER/REPO/pull/123

A branch name selects the pull request associated with that branch:

$ gh pr view feature/example

With no argument, the command looks for the pull request belonging to the current branch:

$ git branch --show-current
feature/example
$ gh pr view

Checkpoint

Confirm the branch output before using the no-argument form. It is convenient, but it can point at a different pull request after a branch switch. If the branch has no associated pull request, expect an error rather than a guessed result.

4. Include the discussion comments

The normal view shows the main pull request details. Add --comments or -c when the conversation is part of the review:

$ gh pr view 123 --comments --repo OWNER/REPO

Warning

Comments can be long and can contain untrusted text copied from an issue or commit. Treat URLs, shell commands and suggested configuration as review material, not instructions to run. This command only fetches and prints them.

5. Ask for stable JSON fields

Use --json when another command or a script needs selected fields. It also saves you from parsing headings and prose in the default display:

$ gh pr view 123 --repo OWNER/REPO \
    --json number,title,state,author,baseRefName,headRefName,url
{"number":123,"title":"Improve example","state":"OPEN","author":{"login":"contributor"},"baseRefName":"main","headRefName":"feature/example","url":"https://github.com/OWNER/REPO/pull/123"}

The real JSON is compact, and the author object can hold more data than shown. gh pr view --help lists the available field names, including body, files, reviews, reviewDecision, statusCheckRollup and updatedAt.

Tip

Do not assume an omitted field is false, empty or unchanged. Request the field you need and handle missing or null data in the consuming script.

6. Filter or format the JSON

Add --jq to extract a value from the JSON. It gives you a quick check without turning the full response into a shell-parsed string:

$ gh pr view 123 --repo OWNER/REPO --json state,reviewDecision \
    --jq '"state=\(.state) review=\(.reviewDecision // "pending")"'
state=OPEN review=pending

Use // for a deliberate fallback when a field is null. Keep the expression in single quotes so the shell does not expand its punctuation. For a repeatable report with several fields, use --template instead:

$ gh pr view 123 --repo OWNER/REPO \
    --json number,title,state --template '{{.number}}: {{.title}} [{{.state}}]{{"\n"}}'
123: Improve example [OPEN]

Both options format the JSON response and do not request extra fields. Put the field list in --json first.

7. Open the web view deliberately

Use --web or -w when you want the full GitHub page, the visual diff or the browser review controls:

$ gh pr view 123 --repo OWNER/REPO --web
Opening https://github.com/OWNER/REPO/pull/123 in your browser.

This asks the configured browser to open a remote page. Check the repository and number first, especially when the command came from a pasted message. If a browser cannot be opened, use the printed URL or the terminal view instead.

8. Diagnose failures without escalating privileges

A failure usually means the target, authentication, network or repository context needs checking. Start by verifying the target:

$ git remote -v
$ git branch --show-current
$ gh pr view 123 --repo OWNER/REPO
  • Authentication problem. Use the GitHub CLI authentication commands appropriate to your organisation and account. Do not paste a token into a command line, shell history or article.
  • Missing pull request. Check that the number belongs to the named repository and that your account can see it.
  • Non-zero exit status. It is useful to automation, so do not hide it with || true unless the failure is intentionally handled.

Tip

Nothing in these examples changes repository state, so there is no rollback step. If you later add a command that edits, reviews or merges a pull request, treat it as a separate state-changing operation and confirm the target before running it.

Done means

  • Command checked. You confirmed the installed gh version and help output.
  • Right pull request. You selected it by number, URL, branch or current checkout.
  • Output controlled. You know when to add --comments and how to limit output with --json.
  • No scraping. You can use --jq or --template instead of parsing human-readable output.
  • Repository checked. You verified it before opening a browser page or acting on copied review text.
  • Read-only. You only read or displayed data, with no merge, review, edit or service change.