Skip to content

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.

API method documentation

owner
required
string

The account owner of the repository. The name is not case sensitive.

repo
required
string

The name of the repository without the .git extension. The name is not case sensitive.

ref
required
string

The Git reference. For more information, see “Git References” in the Git documentation.

Example
heads/feature-a
Media type application/json
object
sha
required

The SHA1 value to set this reference to

string
force

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.

boolean
Examples
Example default
{
"sha": "aa218f56b14c9653891f9e74264a383fa43fefbd",
"force": true
}

Response

Media type application/json
Git Reference

Git references within a repository

object
ref
required
string
node_id
required
string
url
required
string format: uri
object
required
object
type
required
string
sha
required

SHA for the reference

string
>= 40 characters <= 40 characters
url
required
string format: uri
Examples
Example default
{
"ref": "refs/heads/featureA",
"node_id": "MDM6UmVmcmVmcy9oZWFkcy9mZWF0dXJlQQ==",
"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"
}
}

Conflict

Media type application/json
Basic Error

Basic Error

object
message
string
documentation_url
string
url
string
status
string
Example generated
{
"message": "example",
"documentation_url": "example",
"url": "example",
"status": "example"
}

Validation failed, or the endpoint has been spammed.

Media type application/json
Validation Error

Validation Error

object
message
required
string
documentation_url
required
string
errors
Array<object>
object
resource
string
field
string
message
string
code
required
string
index
integer
value
One of:
string
nullable
Example generated
{
"message": "example",
"documentation_url": "example",
"errors": [
{
"resource": "example",
"field": "example",
"message": "example",
"code": "example",
"index": 1,
"value": [
"example"
]
}
]
}