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).
Leave a Reply