Skip to content
LatchkeyLatchkey home

gh pr status: Pull Requests Relevant to You

gh pr status shows the pull request for the current branch plus PRs you opened or need to review.

In automation gh pr status is a quick way to discover the PR tied to the branch a job is running on, without hardcoding a number.

What it does

gh pr status prints three groups: the pull request for the current branch, PRs you created, and PRs requesting your review. With --json it returns the same data as structured fields for scripting.

Common usage

Terminal
gh pr status
gh pr status --json number,title,state
gh pr status -R owner/repo

Flags

FlagWhat it does
--json <fields>Output the current-branch PR as JSON fields
-q, --jq <expression>Filter JSON output with a jq expression
-t, --template <string>Format JSON output with a Go template
-c, --conflict-statusShow merge conflict status
-R, --repo <owner/repo>Target a specific repository

In CI

Export GH_TOKEN and add permissions: { pull-requests: read }. The "created by you" and "requesting a review" groups are empty for github-actions[bot], so in workflows rely on the current-branch PR via --json number rather than the personal groups.

Common errors in CI

"gh: To use GitHub CLI in a GitHub Actions workflow, set the GH_TOKEN environment variable" means GH_TOKEN is unset. "no pull requests found for branch" with --json number returns an empty object; guard against it before reading .number. "could not determine base repository" appears outside a git checkout; pass -R owner/repo.

Using this in CI

CI checkouts are shallow and detached by default, which changes the answer this command gives you. Commands that read history, branch names, or tags need the checkout configured for it.

.github/workflows/ci.yml
- uses: actions/checkout@v4
  with:
    fetch-depth: 0   # history, tags, and git describe all need this

- run: |
    git rev-parse --is-shallow-repository   # expect false
    git rev-parse --abbrev-ref HEAD          # prints HEAD when detached

Frequently asked questions

gh pr status: Pull Requests Relevant to You?
In automation gh pr status is a quick way to discover the PR tied to the branch a job is running on, without hardcoding a number.
What it does?
gh pr status prints three groups: the pull request for the current branch, PRs you created, and PRs requesting your review. With --json it returns the same data as structured fields for scripting.
In CI?
Export GH_TOKEN and add permissions: { pull-requests: read }. The "created by you" and "requesting a review" groups are empty for github-actions[bot], so in workflows rely on the current-branch PR via --json number rather than the personal groups.
Common errors in CI?
"gh: To use GitHub CLI in a GitHub Actions workflow, set the GH_TOKEN environment variable" means GH_TOKEN is unset. "no pull requests found for branch" with --json number returns an empty object; guard against it before reading .number. "could not determine base repository" appears outside a git checkout; pass -R owner/repo.

Related guides

References

Run this faster and cheaper on Latchkey managed runners - self-healing included. Start free → 30-day trial · No credit card