How to get all branches which contain a commit(from SHA) using GithubAPI?

Is there any way using Github API i can get all the branches which contain a specific commit.? 


Hey @thelayman,

Thanks for being here! I don’t think there is a more elegant way to accomplish this than the following: 

  1. Fetch all the commits for a specific branch
  2. Iterate through the commits to see if a specific commit is in the list. To do that, make a request to /repos/:owner/:repo/commits?sha=branchname, where branchname is the name of the branch you want to fetch commits for e.g.

I’ll dig a little deeper and see if there is any other way, 


@andreagriffiths11 For a repo having thousand of commits the process of iterating through will be too slow. Is there a better way to do this?

I know, Github Web UI uses an internal API to do this. for eg.
Is that trustworthy?

I think Github should expose this as a rest API.

1 Like

@andreagriffiths11 @vishmegh88 
did you guys got any solution for this?
I am also looking for API where I can get branch details if we query with commit id. 

Hello @andreagriffiths11 

I want my branch to commit from my repository

I check with your API example

it will work fine 

but when I try with my data like

it will not work

can you guide me proper solution

If you visit
you will see


* message: "Not Found",

* documentation_url: ""


Reason: project ‘DudhatShivam/drphysio’ does not exist on (may be private, if private you should try curl -X GET -u “username:password” YOUR_URL)

  • Following documentation_url:
  • You could try: URL1/commits?sha=master
  • and URL1/commits
  • Their outputs is the same (because ?sha=master is default).

:wave: Following up from @andreagriffiths11’s example, I think it may be worth checking out this topic’s reply for an approach using the GraphQL API:

Also, this approach using the REST API might be of interest too:

1 Like