• Skip to primary navigation
  • Skip to main content
Sal Ferrarello
  • About Sal Ferrarello
  • Speaking
  • Connect
    Mastodon GitHub Twitter (deprecated)
You are here: Home / Dev Tips / Get GitHub PR Number from Current Branch

Get GitHub PR Number from Current Branch

Last updated on June 3, 2025 by Sal Ferrarello

When scripting a task using the GitHub CLI, I found I needed the Pull Request (PR) number for my current branch (technically my current commit). This is the command I needed:

gh pr view --json number --jq '.number'

By checking out the branch I was interested in and then running this command, I got the information I needed.

Limitation

If the commit you’re currently on is used for two different PRs, (e.g. one PR going into main and another going into develop), you’ll only get the most recent one (the one with the highest number).

Sal Ferrarello
Sal Ferrarello (@salcode)
Sal is a PHP and JavaScript developer with a focus on the WordPress platform. He is a conference speaker with a background including Piano Player, Radio DJ, Magician/Juggler, Beach Photographer, and High School Math Teacher. Sal can be found professionally at WebDevStudios, where he works as a principal engineer.

Filed Under: Computing, Dev Tips, Solution Tagged With: bash script, command line, GitHub, GitHub CLI

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Copyright © 2026 · Bootstrap4 Genesis on Genesis Framework · WordPress · Log in