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

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

1 Reply
Highlighted
Community Manager
Message 2 of 2

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, 

Thanks for being here, sharing, and keeping our community awesome!
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!