GitHub - List Commits using the gh api command

by
Jeremy Canfield |
Updated: June 01 2025
| GitHub articles
The gh api command can be used to list the commits 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
The following command can be used to list the commits in a repo, replacing OWNER with the name of your organization and REPO with the name of your repo.
gh api \
--header "Accept: application/vnd.github+json" \
--header "X-GitHub-Api-Version: 2022-11-28" \
/repos/OWNER/REPO/commits
A commit ID number can be used to return a specific commit.
gh api \
--header "Accept: application/vnd.github+json" \
--header "X-GitHub-Api-Version: 2022-11-28" \
/repos/OWNER/REPO/commits/2fa7955f721c0b9fe30c0c456923757cc9b7fd30
Did you find this article helpful?
If so, consider buying me a coffee over at