
The gh pr list command can be used to list the pull requests in a repository. But first, you must use the gh auth login command to log into GitHub. Check out my article FreeKB - GitHub - Log into GitHub using the gh auth login command.
gh auth login
If there are no open pull request, something like this should be displayed. With no additional options, only open pull requests will be displayed.
~]$ gh pr list
no open pull requests in johndoe/my_repo
The --state all option can be used to display all open and closed pull requests.
~]$ gh pr list --state all
Showing 2 of 2 pull requests in johndoe/my_repo that match your search
ID TITLE BRANCH CREATED AT
#2 merge the feature/bar branch into the main branch feature/bar about 11 minutes ago
#1 merge the feature/foo branch into the main branch feature/foo about 5 days ago
The --json number option can be used to list the pull request numbers. By default, this will only list the pull requests that are currently open.
]$ gh pr list --json number
[
{
"number": 20
},
{
"number": 19
}
]
Here is a oneliner that should return the latest, open pull request number.
]$ gh pr list --json number --jq '.[].number' | head -1
20
The gh pr view command can be used to display details for a particular pull request.
~]$ gh pr view 20
version 1.0.13 foo/bar#20
Open • john_doe wants to merge 1 commit into main from tmp_branch_20250227_112049 • about 19 minutes ago
+0 -0 • × 1/2 checks failing
Reviewers: acme/engineering (Requested)
Auto-merge: enabled by cicd_pipeline, using a merge commit
foo.txt
bar.txt
View this pull request on GitHub: https://github.com/acme/foo/pull/20
Here is now you can list the files that were updated in the pull request in JSON format.
~]$ gh pr view 20 --json files
{
"files": [
{
"path": "foo.txt",
"additions": 0,
"deletions": 0
},
{
"path": "bar.txt",
"additions": 0,
"deletions": 0
}
]
}
And to just return the file names.
]$ gh pr view 20 --json files --jq '.files.[].path'
foo.txt
bar.txt
xargs if you want to join the results into a whitespace separated single line.
~]$ gh pr view 20 --json files --jq '.files.[].path' | xargs
foo.txt bar.txt
Did you find this article helpful?
If so, consider buying me a coffee over at