0

I have a sha1 of a git commit on GitHub and i need to understand to what branch that commit belongs through GitHub API.

For example we have this repo - https://github.com/mono/gtk-sharp/commits/master and example commit that isn't HEAD - GitHub API and UI

GitHub has a nice preview APIs there - https://developer.github.com/changes/2019-04-11-pulls-branches-for-commit/ and here but they are working only for commit that is a HEAD so i can't use it.

GitHub also has some kind of internal API for that as in UI that information is displayed here on screenshot below. I can get that data from https://github.com/mono/gtk-sharp/branch_commits/3d0d5a9670c897d5353a99c67d519e9fc6dbcb8e but it's not official API and i can't normally use it with GitHub Token for private repositories.

enter image description here

It's also doable through git branch -r --contains <commmit> but it requires to have that git repository locally and i can't use that approach.

I couldn't find anything for that in neither GitHub REST or GraphQL APIs so any ideas would be appreciated. I probably can get list of commits of all branches and then traverse them to find it but it would be too slow. Also there was older question here but maybe something changed in last 5 years.

Thanks.

Sergey Litvinov
  • 7,408
  • 5
  • 46
  • 67
  • 1
    Yet another old answer: https://stackoverflow.com/a/23970412/7976758 – phd Jan 28 '21 at 21:54
  • This is not a part of the API because in general, it can be very slow. – bk2204 Jan 29 '21 at 01:45
  • @bk2204 it makes sense why it could be very slow, but i was hoping since the same data is displayed on GitHub UI page for each commit, it can be exposed through API as well. but yeah, i understand the reasons – Sergey Litvinov Jan 29 '21 at 10:15

0 Answers0