{"meta":{"title":"REST API endpoints for Git references","intro":"Use the REST API to interact with references in your Git database on GitHub","product":"REST API","breadcrumbs":[{"href":"/en/rest","title":"REST API"},{"href":"/en/rest/git","title":"Git database"},{"href":"/en/rest/git/refs","title":"References"}],"documentType":"article"},"body":"# REST API endpoints for Git references\n\nUse the REST API to interact with references in your Git database on GitHub\n\n## About Git references\n\nA 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](https://git-scm.com/book/en/v2/Git-Internals-Git-References) to your Git database on GitHub.\n\n> [!NOTE]\n> Most endpoints use `Authorization: Bearer <YOUR-TOKEN>` and `Accept: application/vnd.github+json` headers, plus `X-GitHub-Api-Version: 2022-11-28`. Curl examples below omit these standard headers for brevity.\n\n\n## List matching references\n\n```\nGET /repos/{owner}/{repo}/git/matching-refs/{ref}\n```\n\nReturns an array of references from your Git database that match the supplied name. The :ref in the URL must be formatted as heads/<branch name> for branches and tags/<tag name> for tags. If the :ref doesn't exist in the repository, but existing refs start with :ref, they will be returned as an array.\nWhen 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.\nNote\n\nYou 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\".\n\nIf 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.\n\n\n### Parameters\n\n\n#### Headers\n\n\n- **`accept`** (string)\n  Setting to `application/vnd.github+json` is recommended.\n\n\n\n#### Path and query parameters\n\n- **`owner`** (string) (required)\n  The account owner of the repository. The name is not case sensitive.\n\n- **`repo`** (string) (required)\n  The name of the repository without the .git extension. The name is not case sensitive.\n\n- **`ref`** (string) (required)\n  The Git reference. For more information, see \"Git References\" in the Git documentation.\n\n\n\n\n\n\n### HTTP response status codes\n\n\n- **200** - OK\n\n\n- **409** - Conflict\n\n\n\n\n### Code examples\n\n\n\n#### Example\n\n**Request:**\n\n```curl\ncurl -L \\\n  -X GET \\\n  https://api.github.com/repos/OWNER/REPO/git/matching-refs/REF\n```\n\n**Response schema (Status: 200):**\n\nArray of `Git Reference`:\n  * `ref`: required, string\n  * `node_id`: required, string\n  * `url`: required, string, format: uri\n  * `object`: required, object:\n    * `type`: required, string\n    * `sha`: required, string, minLength: 40, maxLength: 40\n    * `url`: required, string, format: uri\n\n\n\n\n\n## Get a reference\n\n```\nGET /repos/{owner}/{repo}/git/ref/{ref}\n```\n\nReturns a single reference from your Git database. The :ref in the URL must be formatted as heads/<branch name> for branches and tags/<tag name> for tags. If the :ref doesn't match an existing ref, a 404 is returned.\nNote\n\nYou 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\".\n\n\n### Parameters\n\n\n#### Headers\n\n\n- **`accept`** (string)\n  Setting to `application/vnd.github+json` is recommended.\n\n\n\n#### Path and query parameters\n\n- **`owner`** (string) (required)\n  The account owner of the repository. The name is not case sensitive.\n\n- **`repo`** (string) (required)\n  The name of the repository without the .git extension. The name is not case sensitive.\n\n- **`ref`** (string) (required)\n  The Git reference. For more information, see \"Git References\" in the Git documentation.\n\n\n\n\n\n\n### HTTP response status codes\n\n\n- **200** - OK\n\n\n- **404** - Resource not found\n\n\n- **409** - Conflict\n\n\n\n\n### Code examples\n\n\n\n#### Example\n\n**Request:**\n\n```curl\ncurl -L \\\n  -X GET \\\n  https://api.github.com/repos/OWNER/REPO/git/ref/REF\n```\n\n**Response schema (Status: 200):**\n\n* `ref`: required, string\n* `node_id`: required, string\n* `url`: required, string, format: uri\n* `object`: required, object:\n  * `type`: required, string\n  * `sha`: required, string, minLength: 40, maxLength: 40\n  * `url`: required, string, format: uri\n\n\n\n\n\n## Create a reference\n\n```\nPOST /repos/{owner}/{repo}/git/refs\n```\n\nCreates 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.\n\n\n### Parameters\n\n\n#### Headers\n\n\n- **`accept`** (string)\n  Setting to `application/vnd.github+json` is recommended.\n\n\n\n#### Path and query parameters\n\n- **`owner`** (string) (required)\n  The account owner of the repository. The name is not case sensitive.\n\n- **`repo`** (string) (required)\n  The name of the repository without the .git extension. The name is not case sensitive.\n\n\n\n\n#### Body parameters\n\n- **`ref`** (string) (required)\n  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.\n\n- **`sha`** (string) (required)\n  The SHA1 value for this reference.\n\n\n\n\n\n### HTTP response status codes\n\n\n- **201** - Created\n\n\n- **409** - Conflict\n\n\n- **422** - Validation failed, or the endpoint has been spammed.\n\n\n\n\n### Code examples\n\n\n\n#### Example\n\n**Request:**\n\n```curl\ncurl -L \\\n  -X POST \\\n  https://api.github.com/repos/OWNER/REPO/git/refs \\\n  -d '{\n  \"ref\": \"refs/heads/featureA\",\n  \"sha\": \"aa218f56b14c9653891f9e74264a383fa43fefbd\"\n}'\n```\n\n**Response schema (Status: 201):**\n\nSame response schema as [Get a reference](#get-a-reference).\n\n\n\n\n\n## Update a reference\n\n```\nPATCH /repos/{owner}/{repo}/git/refs/{ref}\n```\n\nUpdates the provided reference to point to a new SHA. For more information, see \"Git References\" in the Git documentation.\n\n\n### Parameters\n\n\n#### Headers\n\n\n- **`accept`** (string)\n  Setting to `application/vnd.github+json` is recommended.\n\n\n\n#### Path and query parameters\n\n- **`owner`** (string) (required)\n  The account owner of the repository. The name is not case sensitive.\n\n- **`repo`** (string) (required)\n  The name of the repository without the .git extension. The name is not case sensitive.\n\n- **`ref`** (string) (required)\n  The Git reference. For more information, see \"Git References\" in the Git documentation.\n\n\n\n\n#### Body parameters\n\n- **`sha`** (string) (required)\n  The SHA1 value to set this reference to\n\n- **`force`** (boolean)\n  Indicates whether to force the update or to make sure the update is a fast-forward update. Leaving this out or setting it to false will make sure you're not overwriting work.\n  Default: `false`\n\n\n\n\n\n### HTTP response status codes\n\n\n- **200** - OK\n\n\n- **409** - Conflict\n\n\n- **422** - Validation failed, or the endpoint has been spammed.\n\n\n\n\n### Code examples\n\n\n\n#### Example\n\n**Request:**\n\n```curl\ncurl -L \\\n  -X PATCH \\\n  https://api.github.com/repos/OWNER/REPO/git/refs/REF \\\n  -d '{\n  \"sha\": \"aa218f56b14c9653891f9e74264a383fa43fefbd\",\n  \"force\": true\n}'\n```\n\n**Response schema (Status: 200):**\n\nSame response schema as [Get a reference](#get-a-reference).\n\n\n\n\n\n## Delete a reference\n\n```\nDELETE /repos/{owner}/{repo}/git/refs/{ref}\n```\n\nDeletes the provided reference.\n\n\n### Parameters\n\n\n#### Headers\n\n\n- **`accept`** (string)\n  Setting to `application/vnd.github+json` is recommended.\n\n\n\n#### Path and query parameters\n\n- **`owner`** (string) (required)\n  The account owner of the repository. The name is not case sensitive.\n\n- **`repo`** (string) (required)\n  The name of the repository without the .git extension. The name is not case sensitive.\n\n- **`ref`** (string) (required)\n  The Git reference. For more information, see \"Git References\" in the Git documentation.\n\n\n\n\n\n\n### HTTP response status codes\n\n\n- **204** - No Content\n\n\n- **409** - Conflict\n\n\n- **422** - Validation failed, an attempt was made to delete the default branch, or the endpoint has been spammed.\n\n\n\n\n### Code examples\n\n\n\n#### Example\n\n**Request:**\n\n```curl\ncurl -L \\\n  -X DELETE \\\n  https://api.github.com/repos/OWNER/REPO/git/refs/REF\n```\n\n**Response schema (Status: 204):**"}