How to create a branch and push files to it with V4 github graphQL api ?

After reading documentation and watching beginneer tutorial of Gitub GraphQL Api’s I have this understanding we need to use mutation to cut a new branch from existing branch but doesn’t know which mutation verb to use. 

and When to use Objects ??

To my understanding, what you’re asking for is not currently possible in the GraphQL v4 API because there isn’t a createBranch mutation. You would have to continue to use the REST v3 API or use git directly.

I hope that helps!

2 Likes

Following should help

mutation AddBranch($input: CreateRefInput!) {
  createRef(input: $input) {
    ref {
      name
    }
  }
}

Query variable

{
  “input”: {
    “clientMutationId”: “1234”,
    “name”: “refs/heads/<new_branch_name>”,
    “oid”: “<commit_sha>”,
    “repositoryId”: “<repository_id>”
  }
}