GitHub v3 REST API

Update branch protection

Protected branches are available in public repositories with GitHub Free and GitHub Free for organizations, and in public and private repositories with GitHub Pro, GitHub Team, GitHub Enterprise Cloud, and GitHub Enterprise Server. For more information, see GitHub’s products in the GitHub Help documentation.

Protecting a branch requires admin or owner permissions to the repository.

Note: Passing new arrays of users and teams replaces their previous values.

Note: The list of users, apps, and teams in total is limited to 100 items.

put
http://HOSTNAME/api/v3/repos/{owner}/{repo}/branches/{branch}/protection

Path Parameters

ownerstringrequired
repostringrequired
branchstringrequired

The name of the branch.

Body

application/json
required_status_checksobject | nullrequired

Require status checks to pass before merging. Set to null to disable.

Show Child Parameters
enforce_adminsboolean | nullrequired

Enforce all configured restrictions for administrators. Set to true to enforce required status checks for repository administrators. Set to null to disable.

required_pull_request_reviewsobject | nullrequired

Require at least one approving review on a pull request, before merging. Set to null to disable.

Show Child Parameters
restrictionsobject | nullrequired

Restrict who can push to the protected branch. User, app, and team restrictions are only available for organization-owned repositories. Set to null to disable.

Show Child Parameters
required_linear_historyboolean

Enforces a linear commit Git history, which prevents anyone from pushing merge commits to a branch. Set to true to enforce a linear commit history. Set to false to disable a linear commit Git history. Your repository must allow squash merging or rebase merging before you can enable a linear commit history. Default: false. For more information, see “Requiring a linear commit history” in the GitHub Help documentation.

allow_force_pushesboolean | null

Permits force pushes to the protected branch by anyone with write access to the repository. Set to true to allow force pushes. Set to false or null to block force pushes. Default: false. For more information, see “Enabling force pushes to a protected branch” in the GitHub Help documentation."

allow_deletionsboolean

Allows deletion of the protected branch by anyone with write access to the repository. Set to false to prevent deletion of the protected branch. Default: false. For more information, see “Enabling force pushes to a protected branch” in the GitHub Help documentation.

required_conversation_resolutionboolean

Requires all conversations on code to be resolved before a pull request can be merged into a branch that matches this rule. Set to false to disable. Default: false.

contextsarray[string]

The list of status checks to require in order to merge into this branch.

Response

application/json

Response

Protected Branch

Branch protections protect branches

urlstring(uri)required
required_status_checksobject

Status Check Policy

Show Child Parameters
required_pull_request_reviewsobject
Show Child Parameters
required_signaturesobject
Show Child Parameters
enforce_adminsobject
* Additional properties are NOT allowed.
Show Child Parameters
required_linear_historyobject
* Additional properties are NOT allowed.
Show Child Parameters
allow_force_pushesobject
* Additional properties are NOT allowed.
Show Child Parameters
allow_deletionsobject
* Additional properties are NOT allowed.
Show Child Parameters
restrictionsobject

Branch Restriction Policy

Show Child Parameters
required_conversation_resolutionobject
* Additional properties are NOT allowed.
Show Child Parameters
put/repos/{owner}/{repo}/branches/{branch}/protection

Body

{ "required_status_checks": { "strict": true, "contexts": [ "continuous-integration/travis-ci" ] }, "enforce_admins": true, "required_pull_request_reviews": { "dismissal_restrictions": { "users": [ "octocat" ], "teams": [ "justice-league" ] }, "dismiss_stale_reviews": true, "require_code_owner_reviews": true, "required_approving_review_count": 2, "bypass_pull_request_allowances": { "users": [ "octocat" ], "teams": [ "justice-league" ] } }, "restrictions": { "users": [ "octocat" ], "teams": [ "justice-league" ], "apps": [ "super-ci" ] }, "required_linear_history": true, "allow_force_pushes": true, "allow_deletions": true, "required_conversation_resolution": true }
 
application/json

Delete branch protection

Protected branches are available in public repositories with GitHub Free and GitHub Free for organizations, and in public and private repositories with GitHub Pro, GitHub Team, GitHub Enterprise Cloud, and GitHub Enterprise Server. For more information, see GitHub’s products in the GitHub Help documentation.

delete
http://HOSTNAME/api/v3/repos/{owner}/{repo}/branches/{branch}/protection

Path Parameters

ownerstringrequired
repostringrequired
branchstringrequired

The name of the branch.

Response

Response

delete/repos/{owner}/{repo}/branches/{branch}/protection
 

Get admin branch protection

Protected branches are available in public repositories with GitHub Free and GitHub Free for organizations, and in public and private repositories with GitHub Pro, GitHub Team, GitHub Enterprise Cloud, and GitHub Enterprise Server. For more information, see GitHub’s products in the GitHub Help documentation.

get
http://HOSTNAME/api/v3/repos/{owner}/{repo}/branches/{branch}/protection/enforce_admins

Path Parameters

ownerstringrequired
repostringrequired
branchstringrequired

The name of the branch.

Response

200 application/json

Response

Protected Branch Admin Enforced

Protected Branch Admin Enforced

urlstring(uri)required

Example:https://api.github.com/repos/octocat/Hello-World/branches/master/protection/enforce_admins

enabledbooleanrequired

Example:true

get/repos/{owner}/{repo}/branches/{branch}/protection/enforce_admins
 
200 application/json

Set admin branch protection

Protected branches are available in public repositories with GitHub Free and GitHub Free for organizations, and in public and private repositories with GitHub Pro, GitHub Team, GitHub Enterprise Cloud, and GitHub Enterprise Server. For more information, see GitHub’s products in the GitHub Help documentation.

Adding admin enforcement requires admin or owner permissions to the repository and branch protection to be enabled.

post
http://HOSTNAME/api/v3/repos/{owner}/{repo}/branches/{branch}/protection/enforce_admins

Path Parameters

ownerstringrequired
repostringrequired
branchstringrequired

The name of the branch.

Response

200 application/json

Response

Protected Branch Admin Enforced

Protected Branch Admin Enforced

urlstring(uri)required

Example:https://api.github.com/repos/octocat/Hello-World/branches/master/protection/enforce_admins

enabledbooleanrequired

Example:true

post/repos/{owner}/{repo}/branches/{branch}/protection/enforce_admins
 
200 application/json

Delete admin branch protection

Protected branches are available in public repositories with GitHub Free and GitHub Free for organizations, and in public and private repositories with GitHub Pro, GitHub Team, GitHub Enterprise Cloud, and GitHub Enterprise Server. For more information, see GitHub’s products in the GitHub Help documentation.

Removing admin enforcement requires admin or owner permissions to the repository and branch protection to be enabled.

delete
http://HOSTNAME/api/v3/repos/{owner}/{repo}/branches/{branch}/protection/enforce_admins

Path Parameters

ownerstringrequired
repostringrequired
branchstringrequired

The name of the branch.

Response

Response

delete/repos/{owner}/{repo}/branches/{branch}/protection/enforce_admins