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.
GET /repos/{owner}/{repo}/branches
accept (string)application/vnd.github+json is recommended.owner (string) (required)
The account owner of the repository. The name is not case sensitive.
repo (string) (required)
The name of the repository without the .git extension. The name is not case sensitive.
protected (boolean)
Setting to true returns only branches protected by branch protections or rulesets. When set to false, only unprotected branches are returned. Omitting this parameter returns all branches.
per_page (integer)
The number of results per page (max 100). For more information, see "Using pagination in the REST API."
Default: 30
page (integer)
The page number of the results to fetch. For more information, see "Using pagination in the REST API."
Default: 1
200 - OK
404 - Resource not found
Request:
curl -L \
-X GET \
https://api.github.com/repos/OWNER/REPO/branches
Response schema (Status: 200):
Array of Short Branch:
name: required, stringcommit: required, object:
sha: required, stringurl: required, string, format: uriprotected: required, booleanprotection: Branch Protection:
url: stringenabled: booleanrequired_status_checks: Protected Branch Required Status Check:
url: stringenforcement_level: stringcontexts: required, array of stringchecks: required, array of objects:
context: required, stringapp_id: required, integer or nullcontexts_url: stringstrict: booleanenforce_admins: Protected Branch Admin Enforced:
url: required, string, format: urienabled: required, booleanrequired_pull_request_reviews: Protected Branch Pull Request Review:
url: string, format: uridismissal_restrictions: object:
users: array of objectteams: array of objectapps: array of object or nullurl: stringusers_url: stringteams_url: stringbypass_pull_request_allowances: object:
users: array of objectteams: array of objectapps: array of object or nulldismiss_stale_reviews: required, booleanrequire_code_owner_reviews: required, booleanrequired_approving_review_count: integer, minimum: 0, maximum: 6require_last_push_approval: boolean, default: falserestrictions: Branch Restriction Policy:
url: required, string, format: uriusers_url: required, string, format: uriteams_url: required, string, format: uriapps_url: required, string, format: uriusers: required, array of objects:
login: stringid: integer, format: int64node_id: stringavatar_url: stringgravatar_id: stringurl: stringhtml_url: stringfollowers_url: stringfollowing_url: stringgists_url: stringstarred_url: stringsubscriptions_url: stringorganizations_url: stringrepos_url: stringevents_url: stringreceived_events_url: stringtype: stringsite_admin: booleanuser_view_type: stringteams: required, array of Team:
id: required, integernode_id: required, stringname: required, stringslug: required, stringdescription: required, string or nullprivacy: stringnotification_setting: stringpermission: required, stringpermissions: objecturl: required, string, format: urihtml_url: required, string, format: urimembers_url: required, stringrepositories_url: required, string, format: uritype: required, string, enum: enterprise, organizationaccess_source: string, enum: direct, organization, enterpriseorganization_id: integerenterprise_id: integerparent: required, any of:
apps: required, array of objects:
id: integerslug: stringnode_id: stringowner: objectname: stringclient_id: stringdescription: stringexternal_url: stringhtml_url: stringcreated_at: stringupdated_at: stringpermissions: objectevents: array of stringrequired_linear_history: object:
enabled: booleanallow_force_pushes: object:
enabled: booleanallow_deletions: object:
enabled: booleanblock_creations: object:
enabled: booleanrequired_conversation_resolution: object:
enabled: booleanname: stringprotection_url: stringrequired_signatures: object:
url: required, string, format: urienabled: required, booleanlock_branch: object:
enabled: boolean, default: falseallow_fork_syncing: object:
enabled: boolean, default: falseprotection_url: string, format: uriGET /repos/{owner}/{repo}/branches/{branch}
accept (string)application/vnd.github+json is recommended.owner (string) (required)
The account owner of the repository. The name is not case sensitive.
repo (string) (required)
The name of the repository without the .git extension. The name is not case sensitive.
branch (string) (required)
The name of the branch. Cannot contain wildcard characters. To use wildcard characters in branch names, use the GraphQL API.
200 - OK
301 - Moved permanently
404 - Resource not found
Request:
curl -L \
-X GET \
https://api.github.com/repos/OWNER/REPO/branches/BRANCH
Response schema (Status: 200):
name: required, stringcommit: required, Commit:
url: required, string, format: urisha: required, stringnode_id: required, stringhtml_url: required, string, format: uricomments_url: required, string, format: uricommit: required, object:
url: required, string, format: uriauthor: required, any of:
name: stringemail: stringdate: string, format: date-timecommitter: required, any of:
message: required, stringcomment_count: required, integertree: required, object:
sha: required, stringurl: required, string, format: uriverification: Verification:
verified: required, booleanreason: required, stringpayload: required, string or nullsignature: required, string or nullverified_at: required, string or nullauthor: required, one of:
name: string or nullemail: string or nulllogin: required, stringid: required, integer, format: int64node_id: required, stringavatar_url: required, string, format: urigravatar_id: required, string or nullurl: required, string, format: urihtml_url: required, string, format: urifollowers_url: required, string, format: urifollowing_url: required, stringgists_url: required, stringstarred_url: required, stringsubscriptions_url: required, string, format: uriorganizations_url: required, string, format: urirepos_url: required, string, format: urievents_url: required, stringreceived_events_url: required, string, format: uritype: required, stringsite_admin: required, booleanstarred_at: stringuser_view_type: stringcommitter: required, one of:
parents: required, array of objects:
sha: required, stringurl: required, string, format: urihtml_url: string, format: uristats: object:
additions: integerdeletions: integertotal: integerfiles: array of Diff Entry:
sha: required, string or nullfilename: required, stringstatus: required, string, enum: added, removed, modified, renamed, copied, changed, unchangedadditions: required, integerdeletions: required, integerchanges: required, integerblob_url: required, string, format: uriraw_url: required, string, format: uricontents_url: required, string, format: uripatch: stringprevious_filename: string_links: required, object:
html: required, stringself: required, string, format: uriprotected: required, booleanprotection: required, Branch Protection:
url: stringenabled: booleanrequired_status_checks: Protected Branch Required Status Check:
url: stringenforcement_level: stringcontexts: required, array of stringchecks: required, array of objects:
context: required, stringapp_id: required, integer or nullcontexts_url: stringstrict: booleanenforce_admins: Protected Branch Admin Enforced:
url: required, string, format: urienabled: required, booleanrequired_pull_request_reviews: Protected Branch Pull Request Review:
url: string, format: uridismissal_restrictions: object:
users: array of Simple User (see above)teams: array of Team:
id: required, integernode_id: required, stringname: required, stringslug: required, stringdescription: required, string or nullprivacy: stringnotification_setting: stringpermission: required, stringpermissions: objecturl: required, string, format: urihtml_url: required, string, format: urimembers_url: required, stringrepositories_url: required, string, format: uritype: required, string, enum: enterprise, organizationaccess_source: string, enum: direct, organization, enterpriseorganization_id: integerenterprise_id: integerparent: required, any of:
apps: array of GitHub app:
id: required, integerslug: stringnode_id: required, stringclient_id: stringowner: required, one of:
name: required, stringdescription: required, string or nullexternal_url: required, string, format: urihtml_url: required, string, format: uricreated_at: required, string, format: date-timeupdated_at: required, string, format: date-timepermissions: required, object, additional properties: stringevents: required, array of stringinstallations_count: integerurl: stringusers_url: stringteams_url: stringbypass_pull_request_allowances: object:
users: array of Simple User (see above)teams: array of Team (see above)apps: array of GitHub app (see above)dismiss_stale_reviews: required, booleanrequire_code_owner_reviews: required, booleanrequired_approving_review_count: integer, minimum: 0, maximum: 6require_last_push_approval: boolean, default: falserestrictions: Branch Restriction Policy:
url: required, string, format: uriusers_url: required, string, format: uriteams_url: required, string, format: uriapps_url: required, string, format: uriusers: required, array of objects:
login: stringid: integer, format: int64node_id: stringavatar_url: stringgravatar_id: stringurl: stringhtml_url: stringfollowers_url: stringfollowing_url: stringgists_url: stringstarred_url: stringsubscriptions_url: stringorganizations_url: stringrepos_url: stringevents_url: stringreceived_events_url: stringtype: stringsite_admin: booleanuser_view_type: stringteams: required, array of Team (see above)apps: required, array of objects:
id: integerslug: stringnode_id: stringowner: object:
login: stringid: integernode_id: stringurl: stringrepos_url: stringevents_url: stringhooks_url: stringissues_url: stringmembers_url: stringpublic_members_url: stringavatar_url: stringdescription: stringgravatar_id: stringhtml_url: stringfollowers_url: stringfollowing_url: stringgists_url: stringstarred_url: stringsubscriptions_url: stringorganizations_url: stringreceived_events_url: stringtype: stringsite_admin: booleanuser_view_type: stringname: stringclient_id: stringdescription: stringexternal_url: stringhtml_url: stringcreated_at: stringupdated_at: stringpermissions: object:
metadata: stringcontents: stringissues: stringsingle_file: stringevents: array of stringrequired_linear_history: object:
enabled: booleanallow_force_pushes: object:
enabled: booleanallow_deletions: object:
enabled: booleanblock_creations: object:
enabled: booleanrequired_conversation_resolution: object:
enabled: booleanname: stringprotection_url: stringrequired_signatures: object:
url: required, string, format: urienabled: required, booleanlock_branch: object:
enabled: boolean, default: falseallow_fork_syncing: object:
enabled: boolean, default: falseprotection_url: required, string, format: uripattern: stringrequired_approving_review_count: integerPOST /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.
accept (string)application/vnd.github+json is recommended.owner (string) (required)
The account owner of the repository. The name is not case sensitive.
repo (string) (required)
The name of the repository without the .git extension. The name is not case sensitive.
branch (string) (required)
The name of the branch. Cannot contain wildcard characters. To use wildcard characters in branch names, use the GraphQL API.
new_name (string) (required)201 - Created
403 - Forbidden
404 - Resource not found
422 - Validation failed, or the endpoint has been spammed.
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.
POST /repos/{owner}/{repo}/merge-upstream
Sync a branch of a forked repository to keep it up-to-date with the upstream repository.
accept (string)application/vnd.github+json is recommended.owner (string) (required)
The account owner of the repository. The name is not case sensitive.
repo (string) (required)
The name of the repository without the .git extension. The name is not case sensitive.
branch (string) (required)200 - The branch has been successfully synced with the upstream repository
409 - The branch could not be synced because of a merge conflict
422 - The branch could not be synced for some other reason
Request:
curl -L \
-X POST \
https://api.github.com/repos/OWNER/REPO/merge-upstream \
-d '{
"branch": "main"
}'
Response schema (Status: 200):
message: stringmerge_type: string, enum: merge, fast-forward, nonebase_branch: stringPOST /repos/{owner}/{repo}/merges
accept (string)application/vnd.github+json is recommended.owner (string) (required)
The account owner of the repository. The name is not case sensitive.
repo (string) (required)
The name of the repository without the .git extension. The name is not case sensitive.
base (string) (required)
The name of the base branch that the head will be merged into.
head (string) (required)
The head to merge. This can be a branch name or a commit SHA1.
commit_message (string)
Commit message to use for the merge commit. If omitted, a default message will be used.
201 - Successful Response (The resulting merge commit)
204 - Response when already merged
403 - Forbidden
404 - Not Found when the base or head does not exist
409 - Conflict when there is a merge conflict
422 - Validation failed, or the endpoint has been spammed.
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):
url: required, string, format: urisha: required, stringnode_id: required, stringhtml_url: required, string, format: uricomments_url: required, string, format: uricommit: required, object:
url: required, string, format: uriauthor: required, any of:
name: stringemail: stringdate: string, format: date-timecommitter: required, any of:
message: required, stringcomment_count: required, integertree: required, object:
sha: required, stringurl: required, string, format: uriverification: Verification:
verified: required, booleanreason: required, stringpayload: required, string or nullsignature: required, string or nullverified_at: required, string or nullauthor: required, one of:
name: string or nullemail: string or nulllogin: required, stringid: required, integer, format: int64node_id: required, stringavatar_url: required, string, format: urigravatar_id: required, string or nullurl: required, string, format: urihtml_url: required, string, format: urifollowers_url: required, string, format: urifollowing_url: required, stringgists_url: required, stringstarred_url: required, stringsubscriptions_url: required, string, format: uriorganizations_url: required, string, format: urirepos_url: required, string, format: urievents_url: required, stringreceived_events_url: required, string, format: uritype: required, stringsite_admin: required, booleanstarred_at: stringuser_view_type: stringcommitter: required, one of:
parents: required, array of objects:
sha: required, stringurl: required, string, format: urihtml_url: string, format: uristats: object:
additions: integerdeletions: integertotal: integerfiles: array of Diff Entry:
sha: required, string or nullfilename: required, stringstatus: required, string, enum: added, removed, modified, renamed, copied, changed, unchangedadditions: required, integerdeletions: required, integerchanges: required, integerblob_url: required, string, format: uriraw_url: required, string, format: uricontents_url: required, string, format: uripatch: stringprevious_filename: string