REST API endpoints for branches

Use the REST API to modify branches and their protection settings.

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 branches

GET /repos/{owner}/{repo}/branches

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/branches

Response schema (Status: 200):

Array of Short Branch:

Get a branch

GET /repos/{owner}/{repo}/branches/{branch}

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/branches/BRANCH

Response schema (Status: 200):

Rename a branch

POST /repos/{owner}/{repo}/branches/{branch}/rename

Renames a branch in a repository.
Note

Although the API responds immediately, the branch rename process might take some extra time to complete in the background. You won't be able to push to the old branch name while the rename process is in progress. For more information, see "Renaming a branch".

The authenticated user must have push access to the branch. If the branch is the default branch, the authenticated user must also have admin or owner permissions.
In order to rename the default branch, fine-grained access tokens also need the administration:write repository permission.

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/branches/BRANCH/rename \
  -d '{
  "new_name": "my_renamed_branch"
}'

Response schema (Status: 201):

Same response schema as Get a branch.

Sync a fork branch with the upstream repository

POST /repos/{owner}/{repo}/merge-upstream

Sync a branch of a forked repository to keep it up-to-date with the upstream repository.

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/merge-upstream \
  -d '{
  "branch": "main"
}'

Response schema (Status: 200):

Merge a branch

POST /repos/{owner}/{repo}/merges

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/merges \
  -d '{
  "base": "master",
  "head": "cool_feature",
  "commit_message": "Shipped cool_feature!"
}'

Response schema (Status: 201):