PUT /repos/{owner}/{repo}/branches/{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
andteams
replaces their previous values.
[!NOTE] The list of users, apps, and teams in total is limited to 100 items.
Servers
- https://api.github.com
Path parameters
Name | Type | Required | Description |
---|---|---|---|
repo |
String | Yes |
The name of the repository without the |
branch |
String | Yes |
The name of the branch. Cannot contain wildcard characters. To use wildcard characters in branch names, use the GraphQL API. |
owner |
String | Yes |
The account owner of the repository. The name is not case sensitive. |
Request headers
Name | Type | Required | Description |
---|---|---|---|
Content-Type |
String | Yes |
The media type of the request body.
Default value: "application/json" |
Request body fields
Name | Type | Required | Description |
---|---|---|---|
block_creations |
Boolean | No |
If set to |
required_conversation_resolution |
Boolean | No |
Requires all conversations on code to be resolved before a pull request can be merged into a branch that matches this rule. Set to |
required_status_checks |
Object | Yes |
Require status checks to pass before merging. Set to |
required_status_checks.contexts[] |
Array | Yes |
Closing down notice: The list of status checks to require in order to merge into this branch. If any of these checks have recently been set by a particular GitHub App, they will be required to come from that app in future for the branch to merge. Use |
required_status_checks.checks[] |
Array | No |
The list of status checks to require in order to merge into this branch. |
required_status_checks.checks[].context |
String | Yes |
The name of the required check |
required_status_checks.checks[].app_id |
Integer | No |
The ID of the GitHub App that must provide this check. Omit this field to automatically select the GitHub App that has recently provided this check, or any app if it was not set by a GitHub App. Pass -1 to explicitly allow any app to set the status. |
required_status_checks.strict |
Boolean | Yes |
Require branches to be up to date before merging. |
restrictions |
Object | Yes |
Restrict who can push to the protected branch. User, app, and team |
restrictions.teams[] |
Array | Yes |
The list of team |
restrictions.apps[] |
Array | No |
The list of app |
restrictions.users[] |
Array | Yes |
The list of user |
required_pull_request_reviews |
Object | Yes |
Require at least one approving review on a pull request, before merging. Set to |
required_pull_request_reviews.dismiss_stale_reviews |
Boolean | No |
Set to |
required_pull_request_reviews.dismissal_restrictions |
Object | No |
Specify which users, teams, and apps can dismiss pull request reviews. Pass an empty |
required_pull_request_reviews.dismissal_restrictions.teams[] |
Array | No |
The list of team |
required_pull_request_reviews.dismissal_restrictions.apps[] |
Array | No |
The list of app |
required_pull_request_reviews.dismissal_restrictions.users[] |
Array | No |
The list of user |
required_pull_request_reviews.bypass_pull_request_allowances |
Object | No |
Allow specific users, teams, or apps to bypass pull request requirements. |
required_pull_request_reviews.bypass_pull_request_allowances.teams[] |
Array | No |
The list of team |
required_pull_request_reviews.bypass_pull_request_allowances.apps[] |
Array | No |
The list of app |
required_pull_request_reviews.bypass_pull_request_allowances.users[] |
Array | No |
The list of user |
required_pull_request_reviews.required_approving_review_count |
Integer | No |
Specify the number of reviewers required to approve pull requests. Use a number between 1 and 6 or 0 to not require reviewers. |
required_pull_request_reviews.require_last_push_approval |
Boolean | No |
Whether the most recent push must be approved by someone other than the person who pushed it. Default: Default value: false |
required_pull_request_reviews.require_code_owner_reviews |
Boolean | No |
Blocks merging pull requests until code owners review them. |
allow_deletions |
Boolean | No |
Allows deletion of the protected branch by anyone with write access to the repository. Set to |
allow_force_pushes |
Boolean | No |
Permits force pushes to the protected branch by anyone with write access to the repository. Set to |
required_linear_history |
Boolean | No |
Enforces a linear commit Git history, which prevents anyone from pushing merge commits to a branch. Set to |
lock_branch |
Boolean | No |
Whether to set the branch as read-only. If this is true, users will not be able to push to the branch. Default: Default value: false |
enforce_admins |
Boolean | Yes |
Enforce all configured restrictions for administrators. Set to |
allow_fork_syncing |
Boolean | No |
Whether users can pull changes from upstream when the branch is locked. Set to Default value: false |
How to start integrating
- Add HTTP Task to your workflow definition.
- Search for the API you want to integrate with and click on the name.
- This loads the API reference documentation and prepares the Http request settings.
- Click Test request to test run your request to the API and see the API's response.