References API

Get a Reference

GET /repos/:owner/:repo/git/refs/:ref

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 skunkworkz/featureA would be:

GET /repos/:owner/:repo/git/refs/heads/skunkworkz/featureA

Response

Status: 200 OK
X-RateLimit-Limit: 5000
X-RateLimit-Remaining: 4999
{
  "ref": "refs/heads/sc/featureA",
  "url": "https://api.github.com/repos/octocat/Hello-World/git/refs/heads/sc/featureA",
  "object": {
    "type": "commit",
    "sha": "aa218f56b14c9653891f9e74264a383fa43fefbd",
    "url": "https://api.github.com/repos/octocat/Hello-World/git/commits/aa218f56b14c9653891f9e74264a383fa43fefbd"
  }
}

Get all References

GET /repos/:owner/:repo/git/refs

This will return an array of all the references on the system, including things like notes and stashes if they exist on the server. Anything in the namespace, not just heads and tags, though that would be the most common.

You can also request a sub-namespace. For example, to get all the tag references, you can call:

GET /repos/:owner/:repo/git/refs/tags

For a full refs listing, you’ll get something that looks like:

Status: 200 OK
X-RateLimit-Limit: 5000
X-RateLimit-Remaining: 4999
[
  {
    "ref": "refs/heads/master",
    "url": "https://api.github.com/repos/octocat/Hello-World/git/refs/heads/master",
    "object": {
      "type": "commit",
      "sha": "aa218f56b14c9653891f9e74264a383fa43fefbd",
      "url": "https://api.github.com/repos/octocat/Hello-World/git/commits/aa218f56b14c9653891f9e74264a383fa43fefbd"
    }
  },
  {
    "ref": "refs/heads/gh-pages",
    "url": "https://api.github.com/repos/octocat/Hello-World/git/refs/heads/gh-pages",
    "object": {
      "type": "commit",
      "sha": "612077ae6dffb4d2fbd8ce0cccaa58893b07b5ac",
      "url": "https://api.github.com/repos/octocat/Hello-World/git/commits/612077ae6dffb4d2fbd8ce0cccaa58893b07b5ac"
    }
  },
  {
    "ref": "refs/tags/v0.0.1",
    "url": "https://api.github.com/repos/octocat/Hello-World/git/refs/tags/v0.0.1",
    "object": {
      "type": "tag",
      "sha": "940bd336248efae0f9ee5bc7b2d5c985887b16ac",
      "url": "https://api.github.com/repos/octocat/Hello-World/git/tags/940bd336248efae0f9ee5bc7b2d5c985887b16ac"
    }
  }
]

Create a Reference

POST /repos/:owner/: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

Input

{
  "ref": "refs/heads/master",
  "sha": "827efc6d56897b048c772eb4087f854f46256132"
}

Response

Status: 201 Created
X-RateLimit-Limit: 5000
X-RateLimit-Remaining: 4999
{
  "ref": "refs/heads/sc/featureA",
  "url": "https://api.github.com/repos/octocat/Hello-World/git/refs/heads/sc/featureA",
  "object": {
    "type": "commit",
    "sha": "aa218f56b14c9653891f9e74264a383fa43fefbd",
    "url": "https://api.github.com/repos/octocat/Hello-World/git/commits/aa218f56b14c9653891f9e74264a383fa43fefbd"
  }
}

Update a Reference

PATCH /repos/:owner/:repo/git/refs/:ref

Parameters

sha
String of the SHA1 value to set this reference to
force
Boolean indicating whether to force the update or to make sure the update is a fast-forward update. The default is false, so leaving this out or setting it to false will make sure you’re not overwriting work.

Input

{
  "sha": "aa218f56b14c9653891f9e74264a383fa43fefbd",
  "force": true
}

Response

Status: 200 OK
Location: https://api.github.com/git/:owner/:repo/commit/:sha
X-RateLimit-Limit: 5000
X-RateLimit-Remaining: 4999
{
  "ref": "refs/heads/sc/featureA",
  "url": "https://api.github.com/repos/octocat/Hello-World/git/refs/heads/sc/featureA",
  "object": {
    "type": "commit",
    "sha": "aa218f56b14c9653891f9e74264a383fa43fefbd",
    "url": "https://api.github.com/repos/octocat/Hello-World/git/commits/aa218f56b14c9653891f9e74264a383fa43fefbd"
  }
}

Delete a Reference

DELETE /repos/:owner/:repo/git/refs/:ref

Example: Deleting a branch:

DELETE /repos/octocat/Hello-World/git/refs/heads/feature-a

Example: Deleting a tag:

DELETE /repos/octocat/Hello-World/git/refs/tags/v1.0

Response

Status: 204 No Content
X-RateLimit-Limit: 5000
X-RateLimit-Remaining: 4999