Skip to content

Is there a way to get which branch a commit belongs to via GraphQL? #24501

Discussion options

You must be logged in to vote

Instead of that, is there a way to get the branch that a commit belongs to?

👋 @penyuan , thanks for reaching out and asking this question!

Given some commit in a repository, there’s not a way in the GraphQL API to list all of the branches where that commit exists on.

However, one approach that you can take is fetching a list of branches (as the query you provided does) and make another request that lists the commits for one or more of those branches:

query {
  repository(owner: "github", name: "linguist") {
    refs(first: 20, refPrefix: "refs/heads/") {
      totalCount
      edges {
        node {
          name
          target {
            ... on Commit {
              history(firs…

Replies: 13 comments

Comment options

You must be logged in to vote
0 replies
Answer selected
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment