PUT
PUT /repos/{owner}/{repo}/branches/{branch}/protection — GitHub API
GitHub token (required); https://api.github.com
GitHub APIUpdate branch protection
- Base URL
- https://api.github.com
- Auth
- Authorization: Bearer <GITHUB_API_KEY>
- Last verified
- 2026-10-20 · upstream hash matched
Actions Try in browser→
Agents: curl -H "Accept: text/markdown" this URL
→ 494 tokens · Vary: Accept
→ 494 tokens · Vary: Accept
Critical gotchas
GitHub recommends an Accept: application/vnd.github+json header and an explicit X-GitHub-Api-Version header.
Fine-grained tokens only authorize repositories and permissions selected when the token is created.
cURL
curl -X PUT 'https://api.github.com/repos/example-owner/example-repo/branches/example-branch/protection' \ -H "Authorization: Bearer $GITHUB_TOKEN" \ -H 'Accept: application/vnd.github+json' \ -H 'X-GitHub-Api-Version: 2026-03-10' \ -H 'Content-Type: application/json' \ -d '{ "required_status_checks": { "strict": true, "contexts": [ "example-contexts" ], "checks": [ { "context": "example-context", "app_id": 0 } ] }, "enforce_admins": true, "required_pull_request_reviews": { "dismissal_restrictions": { "users": [ "example-users" ], "teams": [ "example-teams" ], "apps": [ "example-apps" ] }, "dismiss_stale_reviews": true, "require_code_owner_reviews": true, "required_approving_review_count": 0, "require_last_push_approval": false, "bypass_pull_request_allowances": { "users": [ "example-users" ], "teams": [ "example-teams" ], "apps": [ "example-apps" ] } }, "restrictions": { "users": [ "example-users" ], "teams": [ "example-teams" ], "apps": [ "example-apps" ] }}'
Parameters
| Name | In | Type | Required | Description |
|---|---|---|---|---|
| owner | path | string | Yes | The account owner of the repository. The name is not case sensitive. |
| repo | path | string | Yes | The name of the repository without the `.git` extension. The name is not case sensitive. |
| branch | path | string | Yes | The name of the branch. Cannot contain wildcard characters. To use wildcard characters in branch names, use [the GraphQL API](https://docs.github.com/graphql). |
| required_status_checks | body | object | Yes | Require status checks to pass before merging. Set to `null` to disable. |
| enforce_admins | body | boolean | Yes | 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_reviews | body | object | Yes | Require at least one approving review on a pull request, before merging. Set to `null` to disable. |
| restrictions | body | object | Yes | 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. |
| required_linear_history | body | boolean | No | 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](https://docs.github.com/github/administering-a-repository/requiring-a-linear-commit-history)" in the GitHub Help documentation. |
| allow_force_pushes | body | boolean | No | 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](https://docs.github.com/github/administering-a-repository/enabling-force-pushes-to-a-protected-branch)" in the GitHub Help documentation." |
| allow_deletions | body | boolean | No | 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](https://docs.github.com/github/administering-a-repository/enabling-force-pushes-to-a-protected-branch)" in the GitHub Help documentation. |
| block_creations | body | boolean | No | If set to `true`, the `restrictions` branch protection settings which limits who can push will also block pushes which create new branches, unless the push is initiated by a user, team, or app which has the ability to push. Set to `true` to restrict new branch creation. Default: `false`. |
| required_conversation_resolution | body | 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 `false` to disable. Default: `false`. |
| lock_branch | body | 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: `false`. |
| allow_fork_syncing | body | boolean | No | Whether users can pull changes from upstream when the branch is locked. Set to `true` to allow fork syncing. Set to `false` to prevent fork syncing. Default: `false`. |
Response 200 OK
{
"url": "https://example.com",
"required_status_checks": {
"url": "https://api.github.com/repos/octocat/Hello-World/branches/master/protection/required_status_checks",
"strict": true,
"contexts": [
"continuous-integration/travis-ci"
],
"checks": [
{
"context": "continuous-integration/travis-ci",
"app_id": 0
}
],
"contexts_url": "https://api.github.com/repos/octocat/Hello-World/branches/master/protection/required_status_checks/contexts"
},
"required_pull_request_reviews": {
"url": "https://example.com",
"dismiss_stale_reviews": true,
"require_code_owner_reviews": true,
"required_approving_review_count": 0,
"require_last_push_approval": false,
"dismissal_restrictions": {
"url": "https://example.com",
"users_url": "https://example.com",
"teams_url": "https://example.com",
"users": [
{
"name": "string",
"email": "string",
"login": "octocat",
"id": 1,
"node_id": "MDQ6VXNlcjE=",
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
"gravatar_id": "41d064eb2195891e12d0413f63227ea7",
"url": "https://api.github.com/users/octocat",
"html_url": "https://github.com/octocat",
"followers_url": "https://api.github.com/users/octocat/followers",
"following_url": "https://api.github.com/users/octocat/following{/other_user}",
"gists_url": "https://api.github.com/users/octocat/gists{/gist_id}",
"starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/octocat/subscriptions",
"organizations_url": "https://api.github.com/users/octocat/orgs",
"repos_url": "https://api.github.com/users/octocat/repos",
"events_url": "https://api.github.com/users/octocat/events{/privacy}",
"received_events_url": "https://api.github.com/users/octocat/received_events",
"type": "User",
"site_admin": true,
"starred_at": "\"2020-07-09T00:17:55Z\"",
"user_view_type": "public"
}
],
"teams": [
{
"id": 0,
"node_id": "string",
"name": "string",
"slug": "string",
"description": "string",
"privacy": "string",
"notification_setting": "string",
"permission": "string",
"permissions": {
"pull": "[recursive or deeply nested schema]",
"triage": "[recursive or deeply nested schema]",
"push": "[recursive or deeply nested schema]",
"maintain": "[recursive or deeply nested schema]",
"admin": "[recursive or deeply nested schema]"
},
"url": "https://example.com",
"html_url": "https://github.com/orgs/rails/teams/core",
"members_url": "string",
"repositories_url": "https://example.com",
"type": "enterprise",
"access_source": "direct",
"organization_id": 37,
"enterprise_id": 42,
"parent": {
"id": "[recursive or deeply nested schema]",
"node_id": "[recursive or deeply nested schema]",
"url": "[recursive or deeply nested schema]",
"members_url": "[recursive or deeply nested schema]",
"name": "[recursive or deeply nested schema]",
"description": "[recursive or deeply nested schema]",
"permission": "[recursive or deeply nested schema]",
"privacy": "[recursive or deeply nested schema]",
"notification_setting": "[recursive or deeply nested schema]",
"html_url": "[recursive or deeply nested schema]",
"repositories_url": "[recursive or deeply nested schema]",
"slug": "[recursive or deeply nested schema]",
"ldap_dn": "[recursive or deeply nested schema]",
"type": "[recursive or deeply nested schema]",
"organization_id": "[recursive or deeply nested schema]",
"enterprise_id": "[recursive or deeply nested schema]"
}
}
],
"apps": [
{
"id": 37,
"slug": "probot-owners",
"node_id": "MDExOkludGVncmF0aW9uMQ==",
"client_id": "\"Iv1.25b5d1e65ffc4022\"",
"owner": {
"name": "[recursive or deeply nested schema]",
"email": "[recursive or deeply nested schema]",
"login": "[recursive or deeply nested schema]",
"id": "[recursive or deeply nested schema]",
"node_id": "[recursive or deeply nested schema]",
"avatar_url": "[recursive or deeply nested schema]",
"gravatar_id": "[recursive or deeply nested schema]",
"url": "[recursive or deeply nested schema]",
"html_url": "[recursive or deeply nested schema]",
"followers_url": "[recursive or deeply nested schema]",
"following_url": "[recursive or deeply nested schema]",
"gists_url": "[recursive or deeply nested schema]",
"starred_url": "[recursive or deeply nested schema]",
"subscriptions_url": "[recursive or deeply nested schema]",
"organizations_url": "[recursive or deeply nested schema]",
"repos_url": "[recursive or deeply nested schema]",
"events_url": "[recursive or deeply nested schema]",
"received_events_url": "[recursive or deeply nested schema]",
"type": "[recursive or deeply nested schema]",
"site_admin": "[recursive or deeply nested schema]",
"starred_at": "[recursive or deeply nested schema]",
"user_view_type": "[recursive or deeply nested schema]"
},
"name": "Probot Owners",
"description": "The description of the app.",
"external_url": "https://example.com",
"html_url": "https://github.com/apps/super-ci",
"created_at": "2017-07-08T16:18:44-04:00",
"updated_at": "2017-07-08T16:18:44-04:00",
"permissions": {
"issues": "read",
"deployments": "write"
},
"events": [
"label",
"deployment"
],
"installations_count": 5
}
]
},
"bypass_pull_request_allowances": {
"users": [
{
"name": "string",
"email": "string",
"login": "octocat",
"id": 1,
"node_id": "MDQ6VXNlcjE=",
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
"gravatar_id": "41d064eb2195891e12d0413f63227ea7",
"url": "https://api.github.com/users/octocat",
"html_url": "https://github.com/octocat",
"followers_url": "https://api.github.com/users/octocat/followers",
"following_url": "https://api.github.com/users/octocat/following{/other_user}",
"gists_url": "https://api.github.com/users/octocat/gists{/gist_id}",
"starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/octocat/subscriptions",
"organizations_url": "https://api.github.com/users/octocat/orgs",
"repos_url": "https://api.github.com/users/octocat/repos",
"events_url": "https://api.github.com/users/octocat/events{/privacy}",
"received_events_url": "https://api.github.com/users/octocat/received_events",
"type": "User",
"site_admin": true,
"starred_at": "\"2020-07-09T00:17:55Z\"",
"user_view_type": "public"
}
],
"teams": [
{
"id": 0,
"node_id": "string",
"name": "string",
"slug": "string",
"description": "string",
"privacy": "string",
"notification_setting": "string",
"permission": "string",
"permissions": {
"pull": "[recursive or deeply nested schema]",
"triage": "[recursive or deeply nested schema]",
"push": "[recursive or deeply nested schema]",
"maintain": "[recursive or deeply nested schema]",
"admin": "[recursive or deeply nested schema]"
},
"url": "https://example.com",
"html_url": "https://github.com/orgs/rails/teams/core",
"members_url": "string",
"repositories_url": "https://example.com",
"type": "enterprise",
"access_source": "direct",
"organization_id": 37,
"enterprise_id": 42,
"parent": {
"id": "[recursive or deeply nested schema]",
"node_id": "[recursive or deeply nested schema]",
"url": "[recursive or deeply nested schema]",
"members_url": "[recursive or deeply nested schema]",
"name": "[recursive or deeply nested schema]",
"description": "[recursive or deeply nested schema]",
"permission": "[recursive or deeply nested schema]",
"privacy": "[recursive or deeply nested schema]",
"notification_setting": "[recursive or deeply nested schema]",
"html_url": "[recursive or deeply nested schema]",
"repositories_url": "[recursive or deeply nested schema]",
"slug": "[recursive or deeply nested schema]",
"ldap_dn": "[recursive or deeply nested schema]",
"type": "[recursive or deeply nested schema]",
"organization_id": "[recursive or deeply nested schema]",
"enterprise_id": "[recursive or deeply nested schema]"
}
}
],
"apps": [
{
"id": 37,
"slug": "probot-owners",
"node_id": "MDExOkludGVncmF0aW9uMQ==",
"client_id": "\"Iv1.25b5d1e65ffc4022\"",
"owner": {
"name": "[recursive or deeply nested schema]",
"email": "[recursive or deeply nested schema]",
"login": "[recursive or deeply nested schema]",
"id": "[recursive or deeply nested schema]",
"node_id": "[recursive or deeply nested schema]",
"avatar_url": "[recursive or deeply nested schema]",
"gravatar_id": "[recursive or deeply nested schema]",
"url": "[recursive or deeply nested schema]",
"html_url": "[recursive or deeply nested schema]",
"followers_url": "[recursive or deeply nested schema]",
"following_url": "[recursive or deeply nested schema]",
"gists_url": "[recursive or deeply nested schema]",
"starred_url": "[recursive or deeply nested schema]",
"subscriptions_url": "[recursive or deeply nested schema]",
"organizations_url": "[recursive or deeply nested schema]",
"repos_url": "[recursive or deeply nested schema]",
"events_url": "[recursive or deeply nested schema]",
"received_events_url": "[recursive or deeply nested schema]",
"type": "[recursive or deeply nested schema]",
"site_admin": "[recursive or deeply nested schema]",
"starred_at": "[recursive or deeply nested schema]",
"user_view_type": "[recursive or deeply nested schema]"
},
"name": "Probot Owners",
"description": "The description of the app.",
"external_url": "https://example.com",
"html_url": "https://github.com/apps/super-ci",
"created_at": "2017-07-08T16:18:44-04:00",
"updated_at": "2017-07-08T16:18:44-04:00",
"permissions": {
"issues": "read",
"deployments": "write"
},
"events": [
"label",
"deployment"
],
"installations_count": 5
}
]
}
},
"required_signatures": {
"url": "https://api.github.com/repos/octocat/Hello-World/branches/master/protection/required_signatures",
"enabled": true
},
"enforce_admins": {
"url": "https://example.com",
"enabled": true
},
"required_linear_history": {
"enabled": true
},
"allow_force_pushes": {
"enabled": true
},
"allow_deletions": {
"enabled": true
},
"restrictions": {
"url": "https://example.com",
"users_url": "https://example.com",
"teams_url": "https://example.com",
"apps_url": "https://example.com",
"users": [
{
"login": "string",
"id": 0,
"node_id": "string",
"avatar_url": "string",
"gravatar_id": "string",
"url": "string",
"html_url": "string",
"followers_url": "string",
"following_url": "string",
"gists_url": "string",
"starred_url": "string",
"subscriptions_url": "string",
"organizations_url": "string",
"repos_url": "string",
"events_url": "string",
"received_events_url": "string",
"type": "string",
"site_admin": true,
"user_view_type": "string"
}
],
"teams": [
{
"id": 0,
"node_id": "string",
"name": "string",
"slug": "string",
"description": "string",
"privacy": "string",
"notification_setting": "string",
"permission": "string",
"permissions": {
"pull": true,
"triage": true,
"push": true,
"maintain": true,
"admin": true
},
"url": "https://example.com",
"html_url": "https://github.com/orgs/rails/teams/core",
"members_url": "string",
"repositories_url": "https://example.com",
"type": "enterprise",
"access_source": "direct",
"organization_id": 37,
"enterprise_id": 42,
"parent": {
"id": 1,
"node_id": "MDQ6VGVhbTE=",
"url": "https://api.github.com/organizations/1/team/1",
"members_url": "https://api.github.com/organizations/1/team/1/members{/member}",
"name": "Justice League",
"description": "A great team.",
"permission": "admin",
"privacy": "closed",
"notification_setting": "notifications_enabled",
"html_url": "https://github.com/orgs/rails/teams/core",
"repositories_url": "https://api.github.com/organizations/1/team/1/repos",
"slug": "justice-league",
"ldap_dn": "uid=example,ou=users,dc=github,dc=com",
"type": "enterprise",
"organization_id": 37,
"enterprise_id": 42
}
}
],
"apps": [
{
"id": 0,
"slug": "string",
"node_id": "string",
"owner": {
"login": "string",
"id": 0,
"node_id": "string",
"url": "string",
"repos_url": "string",
"events_url": "string",
"hooks_url": "string",
"issues_url": "string",
"members_url": "string",
"public_members_url": "string",
"avatar_url": "string",
"description": "string",
"gravatar_id": "\"\"",
"html_url": "\"https://github.com/testorg-ea8ec76d71c3af4b\"",
"followers_url": "\"https://api.github.com/users/testorg-ea8ec76d71c3af4b/followers\"",
"following_url": "\"https://api.github.com/users/testorg-ea8ec76d71c3af4b/following{/other_user}\"",
"gists_url": "\"https://api.github.com/users/testorg-ea8ec76d71c3af4b/gists{/gist_id}\"",
"starred_url": "\"https://api.github.com/users/testorg-ea8ec76d71c3af4b/starred{/owner}{/repo}\"",
"subscriptions_url": "\"https://api.github.com/users/testorg-ea8ec76d71c3af4b/subscriptions\"",
"organizations_url": "\"https://api.github.com/users/testorg-ea8ec76d71c3af4b/orgs\"",
"received_events_url": "\"https://api.github.com/users/testorg-ea8ec76d71c3af4b/received_events\"",
"type": "\"Organization\"",
"site_admin": false,
"user_view_type": "public"
},
"name": "string",
"client_id": "string",
"description": "string",
"external_url": "string",
"html_url": "string",
"created_at": "string",
"updated_at": "string",
"permissions": {
"metadata": "string",
"contents": "string",
"issues": "string",
"single_file": "string"
},
"events": [
"string"
]
}
]
},
"required_conversation_resolution": {
"enabled": true
},
"block_creations": {
"enabled": true
},
"lock_branch": {
"enabled": false
},
"allow_fork_syncing": {
"enabled": false
}
} Get a free GitHub API key → sponsored Affiliate link - we may earn a commission, at no extra cost to you.