REST API endpoints for Git references

Use the REST API to interact with references in your Git database on GitHub

About Git references

A Git reference (git ref) is a file that contains a Git commit SHA-1 hash. When referring to a Git commit, you can use the Git reference, which is an easy-to-remember name, rather than the hash. The Git reference can be rewritten to point to a new commit. A branch is a Git reference that stores the new Git commit hash. These endpoints allow you to read and write references to your Git database on GitHub.

Note

Most endpoints use Authorization: Bearer <YOUR-TOKEN> and Accept: application/vnd.github+json headers, plus X-GitHub-Api-Version: 2026-03-10. Curl examples below omit these standard headers for brevity.

List matching references

GET /repos/{owner}/{repo}/git/matching-refs/{ref}

Returns an array of references from your Git database that match the supplied name. The :ref in the URL must be formatted as heads/ for branches and tags/ for tags. If the :ref doesn't exist in the repository, but existing refs start with :ref, they will be returned as an array.
When you use this endpoint without providing a :ref, it will return an array of all the references from your Git database, including notes and stashes if they exist on the server. Anything in the namespace is returned, not just heads and tags.
Note

You need to explicitly request a pull request to trigger a test merge commit, which checks the mergeability of pull requests. For more information, see "Checking mergeability of pull requests".

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.

Parameters

Headers

Path and query parameters

HTTP response status codes

Code examples

Example

Request:

curl -L \
  -X GET \
  https://api.github.com/repos/OWNER/REPO/git/matching-refs/REF

Response schema (Status: 200):

Array of Git Reference:

Get a reference

GET /repos/{owner}/{repo}/git/ref/{ref}

Returns a single reference from your Git database. The :ref in the URL must be formatted as heads/ for branches and tags/ for tags. If the :ref doesn't match an existing ref, a 404 is returned.
Note

You need to explicitly request a pull request to trigger a test merge commit, which checks the mergeability of pull requests. For more information, see "Checking mergeability of pull requests".

Parameters

Headers

Path and query parameters

HTTP response status codes

Code examples

Example

Request:

curl -L \
  -X GET \
  https://api.github.com/repos/OWNER/REPO/git/ref/REF

Response schema (Status: 200):

Create a reference

POST /repos/{owner}/{repo}/git/refs

Creates a reference for your repository. You are unable to create new references for empty repositories, even if the commit SHA-1 hash used exists. Empty repositories are repositories without branches.

Parameters

Headers

Path and query parameters

Body parameters

HTTP response status codes

Code examples

Example

Request:

curl -L \
  -X POST \
  https://api.github.com/repos/OWNER/REPO/git/refs \
  -d '{
  "ref": "refs/heads/featureA",
  "sha": "aa218f56b14c9653891f9e74264a383fa43fefbd"
}'

Response schema (Status: 201):

Same response schema as Get a reference.

Update a reference

PATCH /repos/{owner}/{repo}/git/refs/{ref}

Updates the provided reference to point to a new SHA. For more information, see "Git References" in the Git documentation.

Parameters

Headers

Path and query parameters

Body parameters

HTTP response status codes

Code examples

Example

Request:

curl -L \
  -X PATCH \
  https://api.github.com/repos/OWNER/REPO/git/refs/REF \
  -d '{
  "sha": "aa218f56b14c9653891f9e74264a383fa43fefbd",
  "force": true
}'

Response schema (Status: 200):

Same response schema as Get a reference.

Delete a reference

DELETE /repos/{owner}/{repo}/git/refs/{ref}

Deletes the provided reference.

Parameters

Headers

Path and query parameters

HTTP response status codes

Code examples

Example

Request:

curl -L \
  -X DELETE \
  https://api.github.com/repos/OWNER/REPO/git/refs/REF

Response schema (Status: 204):