🌐
GitHub
docs.github.com › en › rest › git › refs
REST API endpoints for Git references - GitHub Docs
If you request matching references for a branch named feature but the branch feature doesn't exist, the response can still include other matching head refs that start with the word feature, such as featureA and featureB. This endpoint works with the following fine-grained token types: ... This endpoint can be used without authentication or the aforementioned permissions if only public resources are requested. ... 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/git/matching-refs/REF
🌐
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" } } GET /repos/:owner/:repo/git/refs ·
🌐
GitHub
docs.github.com › enterprise › 11.10.340 › developer › 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" } } GET /repos/:owner/:repo/git/refs ·
🌐
GitHub
github.com › github › docs › blob › main › content › rest › git › refs.md
docs/content/rest/git/refs.md at main · github/docs
REST API endpoints for Git references ... · ghes · * * * API · true · rest · A Git reference (git ref) is a file that contains a Git commit SHA-1 hash....
Author   github
🌐
GitHub
docs.github.com › en › enterprise-server@3.12 › rest › git › refs
REST API endpoints for Git references - GitHub Enterprise Server 3.12 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: 2022-11-28" \ http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/git/refs/REF \ -d '{"sha":"aa218f56b14c9653891f9e74264a383fa43fefbd","force":true}'
🌐
GitHub
docs.github.com › en › enterprise-server@3.3 › rest › guides › using-the-rest-api-to-interact-with-your-git-database
Using the REST API to interact with your Git database - GitHub Enterprise Server 3.3 Docs
Use the REST API to read and write raw Git objects to your Git database on GitHub Enterprise Server and to list and update your references (branch heads and tags).
🌐
GitHub
docs.github.com › en › enterprise-cloud@latest › rest › git › refs
REST API endpoints for Git references - GitHub Enterprise Cloud Docs
If you request matching references for a branch named feature but the branch feature doesn't exist, the response can still include other matching head refs that start with the word feature, such as featureA and featureB. This endpoint works with the following fine-grained token types: ... This endpoint can be used without authentication or the aforementioned permissions if only public resources are requested. If you access GitHub at GHE.com, replace api.github.com with your enterprise's dedicated subdomain at api.SUBDOMAIN.ghe.com.
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)
🌐
GitHub
docs.github.com › en › rest › git
REST API endpoints for Git database - GitHub Docs
Use the REST API to interact with raw Git objects in your Git database on GitHub and to list and update Git references (branch heads and tags).
🌐
GitHub
docs.github.com › en › rest › guides › using-the-rest-api-to-interact-with-your-git-database
Using the REST API to interact with your Git database - GitHub Docs
Use the REST API to read and write raw Git objects to your Git database on GitHub and to list and update your references (branch heads and tags).
Find elsewhere
🌐
GitHub
github.com › orgs › community › discussions › 68932
REST API POST /repos/{owner}/{repo}/git/refs will respond 404 when submit a specific sha · community · Discussion #68932
curl 'https://api.github.com/repos/zjffun/translated-content-dochub/git/refs' \ -H 'authority: api.github.com' \ -H 'accept: application/vnd.github.v3+json' \ -H 'accept-language: en,zh-CN;q=0.9,zh;q=0.8,or;q=0.7,fa;q=0.6' \ -H 'authorization: token gho_xxx' \ -H 'content-type: application/json; charset=utf-8' \ -H 'origin: https://dochub.zjffun.com' \ -H 'referer: https://dochub.zjffun.com/' \ -H 'sec-ch-ua: "Chromium";v="116", "Not)A;Brand";v="24", "Google Chrome";v="116"' \ -H 'sec-ch-ua-mobile: ?0' \ -H 'sec-ch-ua-platform: "macOS"' \ -H 'sec-fetch-dest: empty' \ -H 'sec-fetch-mode: cors'
🌐
GitHub
docs.github.com › en › rest › repos › repos
REST API endpoints for repositories - 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
🌐
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 ·
🌐
Stack Overflow
stackoverflow.com › questions › 71586519 › how-to-get-git-notes-from-github-api
How to get git notes from github API? - Stack Overflow
To be honest, I haven’t tried it myself. But they explicitly mention that calling the LIST api with an empty :ref parameter will return the notes ref as well.
🌐
GitHub
docs.github.com › en › rest › repos › rules
REST API endpoints for rules - 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/rulesets/RULESET_ID ... { "id": 42, "name": "super cool ruleset", "target": "branch", "source_type": "Repository", "source": "monalisa/my-repo", "enforcement": "active", "bypass_actors": [ { "actor_id": 234, "actor_type": "Team", "bypass_mode": "always" } ], "conditions": { "ref_name": { "include": [ "refs/heads/main", "refs/heads/master" ], "exclude": [ "refs/heads/dev*" ] } }, "rules": [ { "type": "commit_author_email_p
🌐
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
developer.github.com › v3 › repos › statuses
REST API endpoints for commit statuses - GitHub Docs
This resource is also available via a legacy route: GET /repos/:owner/:repo/statuses/:ref. This endpoint works with the following fine-grained token types: ... This endpoint can be used without authentication or the aforementioned permissions if only public resources are requested. ... 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/commits/REF/statuses
🌐
GitHub
github.com › google › go-github › issues › 1512
Support new Git reference get/list endpoints · Issue #1512 · google/go-github
April 28, 2020 - GetRefs will mostly behave the same, but will return an empty list instead of an error if no refs match and will duplicate the functionality of ListRefs if an empty refs is used as an argument. The "error on empty" behavior could be retained if desired. ListRefs will behave the same, but is technically redundant. Modify GetRef, leave GetRefs and ListRefs alone, and add a new ListMatchingRefs method. I think this will ultimately be confusing, there are 3 methods that do nearly the same thing, two of which are undocumented in the GitHub API.
Author   bluekeyes