-1

I have a sha lets say "abcdefghijk" . I want to find the exact branch name from where the commit came from . I tried looking for other answers but most of them have some iterations or use command line , the restriction I have is I need to use only GIT API (Rest) to retrieve the branch name .

I tried looking for search API but it gives me commit details and the commit details doesn't contain branch name . Even if I get the pull request from where the commit is coming from would also be helpful . So using GIT API I want to check either the branch name or the pull request from where the commit is coming from .

Any help here is appreciated .

Reason : Why I want to know branch name

So let's say the manifest created for deployment is created from master branch . So let's say there are 2 PR's from a feature branch which was merged to the master branch .

master_branch
     --PR1 (From Feature Branch which has 1 commit)
     --PR2 (From Feature Branch which has 2 commit)

Now those commits will appear in Master Branch .

Now Feature Branch in PR1 had 1 commit made 3 days before deployment . Feature branch in PR 2 has 1 commit made 3 days before and second commit made 11 days before deployment .

I want to know from which branch those commits came from . Reason is I want to know which branch commits took max time to make it to the master branch (ie: Point out the fault branch which took max time to make it to master after first commit ) .

arpit joshi
  • 1,987
  • 8
  • 36
  • 62
  • 2
    There is no Git REST API, and commits aren't "from" branches, let alone unique ones. Are you trying to tie commits to some external administrative record, or what? – jthill Jun 27 '21 at 22:57
  • Updated my question for reason why I want to know the branch names . – arpit joshi Jun 28 '21 at 03:05
  • There is a Git-**HUB** REST API. It is not a Git REST API. There is a Git API of sorts, but it uses the command line, and is not REST. – torek Jun 28 '21 at 14:00

1 Answers1

1

Now those commits will appear in Master Branch .

They will if those PRs have been merged in a fast-forward manner.
If they are merged in a non-fast-forward, resulting in a merge commit (F below), then a git branch --contain <sha1> would still return "feature" (unless the PR branch has been deleted)

https://docs.github.com/assets/images/help/pull_requests/standard-merge-commit-diagram.png

The problem is: The Branch GitHub API does not include a filter for a specific commit, so you might need to get all commits for PR branches (possibly using GraphQL) in order to get that information from API only.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250