v68

latestOpenAPI 3.0.3MITraw.githubusercontent.com2026-08-011,21696712.3 MB
repos

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/repos/{owner}/{repo}/branches/{branch}/protection

Path parameters

ownerstring required

The account owner of the repository. The name is not case sensitive.

repostring required

The name of the repository without the .git extension. The name is not case sensitive.

branchstring required

The name of the branch. Cannot contain wildcard characters. To use wildcard characters in branch names, use the GraphQL API.

Request body

enforce_adminsboolean nullable required

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

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 nullable

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.

block_creationsboolean

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_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.

lock_branchboolean

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_syncingboolean

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

Response

urlstring uri required

Example response

{
  "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"
      }
    ],
    "contexts_url": "https://api.github.com/repos/octocat/Hello-World/branches/master/protection/required_status_checks/contexts"
  },
  "required_pull_request_reviews": {
    "dismissal_restrictions": {
      "users": [
        {
          "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",
          "starred_at": "\"2020-07-09T00:17:55Z\"",
          "user_view_type": "public"
        }
      ],
      "teams": [
        {
          "html_url": "https://github.com/orgs/rails/teams/core",
          "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",
            "organization_id": 37,
            "enterprise_id": 42
          }
        }
      ],
      "apps": [
        {
          "id": 37,
          "slug": "probot-owners",
          "node_id": "MDExOkludGVncmF0aW9uMQ==",
          "client_id": "\"Iv1.25b5d1e65ffc4022\"",
          "owner": {
            "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",
            "starred_at": "\"2020-07-09T00:17:55Z\"",
            "user_view_type": "public"
          },
          "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": [
        {
          "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",
          "starred_at": "\"2020-07-09T00:17:55Z\"",
          "user_view_type": "public"
        }
      ],
      "teams": [
        {
          "html_url": "https://github.com/orgs/rails/teams/core",
          "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",
            "organization_id": 37,
            "enterprise_id": 42
          }
        }
      ],
      "apps": [
        {
          "id": 37,
          "slug": "probot-owners",
          "node_id": "MDExOkludGVncmF0aW9uMQ==",
          "client_id": "\"Iv1.25b5d1e65ffc4022\"",
          "owner": {
            "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",
            "starred_at": "\"2020-07-09T00:17:55Z\"",
            "user_view_type": "public"
          },
          "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
  },
  "restrictions": {
    "teams": [
      {
        "html_url": "https://github.com/orgs/rails/teams/core",
        "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",
          "organization_id": 37,
          "enterprise_id": 42
        }
      }
    ],
    "apps": [
      {
        "owner": {
          "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\"",
          "user_view_type": "public"
        }
      }
    ]
  }
}