The V3 API mentions branches in its reference page

The ref in the URL must be formatted as heads/branch, not just branch.
For example, the call to get the data for a branch named sc/featureA would be:

GET /repos/:user/:repo/git/refs/heads/sc/featureA

Create a Reference

POST /repos/:user/:repo/git/refs

Parameters

ref

String of the name of the fully qualified reference (ie: refs/heads/master). If it doesn’t start with ‘refs’ and have at least two slashes, it will be rejected.

sha

String of the SHA1 value to set this reference to

So it should be possible to create a new branch, by naming a new '/heads' in the ref parameter.


Potherca points out to a working test, using the service of www.hurl.it (which makes HTTP requests)

  • Find the revision you want to branch from.
    Either on Github itself or by doing a GET request from Hurl:

    https://api.github.com/repos/<AUTHOR>/<REPO>/git/refs/heads

  • Copy the revision hash

  • Do a POST request from Hurl to https://api.github.com/repos/<AUTHOR>/<REPO>/git/refs with the following as the POST body :

      {
          "ref": "refs/heads/<NEW-BRANCH-NAME>",
          "sha": "<HASH-TO-BRANCH-FROM>"
      }
    

    (obviously replacing the <NEW-BRANCH-NAME> with the name your want the new branch to have and the <HASH-TO-BRANCH-FROM> with, you know, the hash of the revision you want to branch from)

    You will need to use HTTP basic and fill in your Github credentials to access the Github API.

  • Press the Send button and your branch will be created!


In 2022, you can also use gh api

gh api \
  --method POST \
  -H "Accept: application/vnd.github.v3+json" \
  /repos/OWNER/REPO/git/refs \
  -f ref='refs/heads/featureA'
 -f sha='aa218f56b14c9653891f9e74264a383fa43fefbd'
Answer from VonC on Stack Overflow
🌐
GitHub
developer.github.com › v3 › git › refs
REST API endpoints for Git references - GitHub Docs
For more information, see "Git References" in the Git documentation. This endpoint works with the following fine-grained token types: ... curl -L \ -X PATCH \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2026-03-10" \ https://api.github.com/repos/OWNER/REPO/git/refs/REF \ -d '{"sha":"aa218f56b14c9653891f9e74264a383fa43fefbd","force":true}'
🌐
GitHub
docs2.lfe.io › v3 › git › refs
Git Refs | GitHub API
{ "ref": "refs/heads/featureA", "url": "https://api.github.com/repos/octocat/Hello-World/git/refs/heads/featureA", "object": { "type": "commit", "sha": "aa218f56b14c9653891f9e74264a383fa43fefbd", "url": "https://api.github.com/repos/octocat/Hello-World/git/commits/aa218f56b14c9653891f9e74264a383fa43fefbd" } } ... { "ref": "refs/heads/featureA", "url": "https://api.github.com/repos/octocat/Hello-World/git/refs/heads/featureA", "object": { "type": "commit", "sha": "aa218f56b14c9653891f9e74264a383fa43fefbd", "url": "https://api.github.com/repos/octocat/Hello-World/git/commits/aa218f56b14c9653891f9e74264a383fa43fefbd" } }
Top answer
1 of 5
109

The V3 API mentions branches in its reference page

The ref in the URL must be formatted as heads/branch, not just branch.
For example, the call to get the data for a branch named sc/featureA would be:

GET /repos/:user/:repo/git/refs/heads/sc/featureA

Create a Reference

POST /repos/:user/:repo/git/refs

Parameters

ref

String of the name of the fully qualified reference (ie: refs/heads/master). If it doesn’t start with ‘refs’ and have at least two slashes, it will be rejected.

sha

String of the SHA1 value to set this reference to

So it should be possible to create a new branch, by naming a new '/heads' in the ref parameter.


Potherca points out to a working test, using the service of www.hurl.it (which makes HTTP requests)

  • Find the revision you want to branch from.
    Either on Github itself or by doing a GET request from Hurl:

    https://api.github.com/repos/<AUTHOR>/<REPO>/git/refs/heads

  • Copy the revision hash

  • Do a POST request from Hurl to https://api.github.com/repos/<AUTHOR>/<REPO>/git/refs with the following as the POST body :

      {
          "ref": "refs/heads/<NEW-BRANCH-NAME>",
          "sha": "<HASH-TO-BRANCH-FROM>"
      }
    

    (obviously replacing the <NEW-BRANCH-NAME> with the name your want the new branch to have and the <HASH-TO-BRANCH-FROM> with, you know, the hash of the revision you want to branch from)

    You will need to use HTTP basic and fill in your Github credentials to access the Github API.

  • Press the Send button and your branch will be created!


In 2022, you can also use gh api

gh api \
  --method POST \
  -H "Accept: application/vnd.github.v3+json" \
  /repos/OWNER/REPO/git/refs \
  -f ref='refs/heads/featureA'
 -f sha='aa218f56b14c9653891f9e74264a383fa43fefbd'
2 of 5
8

Adding to @VonC answer, here is working snippet in python.

import requests
headers = {'Authorization': "Token " + 'YOUR_TOKEN_HERE'}
url = "https://api.github.com/repos/<USERNAME>/<REPO>/git/refs/heads"
branches = requests.get(url, headers=headers).json()
branch, sha = branches[-1]['ref'], branches[-1]['object']['sha']
res = requests.post('https://api.github.com/repos/<USERNAME>/<REPO>/git/refs', json={
    "ref": "refs/heads/newbranch",
    "sha": sha
}, headers=headers)
print(res.content)
🌐
Octokit
octokit.github.io › octokit.rb › Octokit › Client › Refs.html
Module: Octokit::Client::Refs —
Methods for References for Git Data API · See Also: https://developer.github.com/v3/git/refs/ #create_ref(repo, ref, sha, options = {}) ⇒ Array<Sawyer::Resource> (also: #create_reference) Create a reference. #delete_branch(repo, branch, options = {}) ⇒ Boolean ·
🌐
GitHub
developer.github.com › v3 › repos › contents
REST API endpoints for repository contents - GitHub Docs
curl -L \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2026-03-10" \ https://api.github.com/repos/OWNER/REPO/tarball/REF
🌐
GitHub
docs.github.com › en › rest › repos
REST API endpoints for repositories - GitHub Docs
REST API endpoints for repository autolinks · Get all autolinks of a repository · Create an autolink reference for a repository · Get an autolink reference of a repository · Delete an autolink reference from a repository · REST API endpoints for repository contents ·
🌐
Readthedocs
github3.readthedocs.io › en › develop › api-reference › repos.html
Repository API Objects — github3.py 1.1.0 documentation
This behaviour is required by the GitHub API. ... Create a tree on this repository. ... Delete this repository. ... Delete the key with the specified id from your deploy keys list. ... Delete the user’s subscription to this repository. ... Retrieve the deployment identified by id. ... Iterate over deployments for this repository. directory_contents(directory_path, ref...
🌐
GitHub
docs.github.com › en › rest
GitHub REST API documentation - GitHub Docs
Create integrations, retrieve data, and automate your workflows with the GitHub REST API.
Find elsewhere
🌐
Stack Overflow
stackoverflow.com › questions › 73922148 › 404-not-found-on-github-api-using-github-rest-git-createref
404 Not Found on Github API using github.rest.git.createRef - Stack Overflow
October 1, 2022 - await github.rest.git.createRef({ owner: context.repo.owner, repo: context.repo.repo, ref: 'refs/heads/' + '${{ github.event.inputs.combineBranchName }}', sha: baseBranchSHA });
🌐
GitHub
docs.github.com › en › rest › pulls › pulls
REST API endpoints for pull requests - GitHub Docs
/Hello-World/events", "forks_url": "https://api.github.com/repos/octocat/Hello-World/forks", "git_commits_url": "https://api.github.com/repos/octocat/Hello-World/git/commits{/sha}", "git_refs_url": "https://api.github.com/repos/octocat/Hello-World/git/refs{/sha}", "git_tags_url": "https://api.github.com/repos/octocat/Hello-World/git/tags{/sha}", "git_url": "git:github.com/octocat/Hello-World.git", "issue_comment_url": "https://api.github.com/repos/octocat/Hello-World/issues/comments{/number}", "issue_events_url": "https://api.github.com/repos/octocat/Hello-World/issues/events{/number}", "issue
🌐
Kohsuke
github-api.kohsuke.org › apidocs › org › kohsuke › github › GHRepository.html
GHRepository (GitHub API for Java 1.324 API)
March 1, 2022 - For example 'jenkinsci/jenkins' in case of http://github.com/jenkinsci/jenkins ... Has pull access boolean. ... Has push access boolean. ... Has admin access boolean. ... Gets the primary programming language. ... Gets owner. ... Gets issue. ... Create issue gh issue builder. ... Gets issues. ... Gets issues. ... Deprecated. ... Lists up all the issues in this repository. ... Retrieves issues. ... Create release gh release builder. ... Creates a named ref, such as tag, branch, etc.
🌐
GitHub
github.com › topics › createref
createref · GitHub Topics
November 28, 2022 - react api reference reactjs callbacks sematic-ui lifecycle-methods createref
🌐
GitHub
github.com › marketplace › actions › create-git-ref
Create Git Ref - GitHub Marketplace
You only need set the variable refs with the value or values separates by commas. It only accepts a git refs format. ... jobs: job-id: runs-on: ubuntu-latest steps: - name: Create a ref uses: Hatzelencio/create-ref@v0.0.3 with: refs: "tags/my-new-ref" # or refs: "heads/my-new-branch" env: GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}