Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Copilot Lvl 3
Message 1 of 3

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.? 

2 Replies
Community Manager
Message 2 of 3

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

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. https://api.github.com/repos/andreagriffiths11/graphql-test/commits?sha=master.

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


Best,
AndreaG

Mark helpful posts with Accept as Solution to help other users locate important info. Don't forget to give Kudos for great content!

Ground Controller Lvl 1
Message 3 of 3

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

@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.
https://github.com/elastic/kibana/branch_commits/6a97f9a7ee797d302cb4f05120ff935bfe22eba0
Is that trustworthy?

I think Github should expose this as a rest API.