get /repos/{owner}/{repo}/branches
Parameters
| Name | Type | In | Description |
|---|---|---|---|
accept |
string | header |
Setting to
|
owner |
string | path | |
repo |
string | path | |
protected |
boolean | query |
Setting to |
per_page |
integer | query |
Results per page (max 100) Default:30 |
page |
integer | query |
Page number of the results to fetch. Default:1 |
Code samples
Shell
curl \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/octocat/hello-world/branchesJavaScript (@octokit/core.js)
await octokit.request('GET /repos/{owner}/{repo}/branches', {
owner: 'octocat',
repo: 'hello-world'
})
Response
Status: 200 OK
[
{
"name": "master",
"commit": {
"sha": "c5b97d5ae6c19d5c5df71a34c7fbeeda2479ccbc",
"url": "https://api.github.com/repos/octocat/Hello-World/commits/c5b97d5ae6c19d5c5df71a34c7fbeeda2479ccbc"
},
"protected": true,
"protection": {
"required_status_checks": {
"enforcement_level": "non_admins",
"contexts": [
"ci-test",
"linter"
]
}
},
"protection_url": "https://api.github.com/repos/octocat/hello-world/branches/master/protection"
}
]
Resource not found
Status: 404 Not Found
Notes
get /repos/{owner}/{repo}/branches/{branch}
Parameters
| Name | Type | In | Description |
|---|---|---|---|
accept |
string | header |
Setting to
|
owner |
string | path | |
repo |
string | path | |
branch |
string | path |
The name of the branch. |
Code samples
Shell
curl \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/octocat/hello-world/branches/BRANCHJavaScript (@octokit/core.js)
await octokit.request('GET /repos/{owner}/{repo}/branches/{branch}', {
owner: 'octocat',
repo: 'hello-world',
branch: 'branch'
})
Response
Status: 200 OK
Moved permanently
Status: 301 Moved Permanently
Resource not found
Status: 404 Not Found
Preview header missing
Status: 415 Unsupported Media Type
Notes
Rename a branch
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 permissions required to use this endpoint depends on whether you are renaming the default branch.
To rename a non-default branch:
- Users must have push access.
- GitHub Apps must have the
contents:writerepository permission.
To rename the default branch:
- Users must have admin or owner permissions.
- GitHub Apps must have the
administration:writerepository permission.
post /repos/{owner}/{repo}/branches/{branch}/rename
Parameters
| Name | Type | In | Description |
|---|---|---|---|
accept |
string | header |
Setting to
|
owner |
string | path | |
repo |
string | path | |
branch |
string | path |
The name of the branch. |
new_name |
string | body |
Required. The new name of the branch. |
Code samples
Shell
curl \
-X POST \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/octocat/hello-world/branches/BRANCH/rename \
-d '{"new_name":"new_name"}'JavaScript (@octokit/core.js)
await octokit.request('POST /repos/{owner}/{repo}/branches/{branch}/rename', {
owner: 'octocat',
repo: 'hello-world',
branch: 'branch',
new_name: 'new_name'
})
Response
Status: 201 Created
{
"name": "master",
"commit": {
"sha": "7fd1a60b01f91b314f59955a4e4d4e80d8edf11d",
"node_id": "MDY6Q29tbWl0N2ZkMWE2MGIwMWY5MWIzMTRmNTk5NTVhNGU0ZDRlODBkOGVkZjExZA==",
"commit": {
"author": {
"name": "The Octocat",
"date": "2012-03-06T15:06:50-08:00",
"email": "octocat@nowhere.com"
},
"url": "https://api.github.com/repos/octocat/Hello-World/git/commits/7fd1a60b01f91b314f59955a4e4d4e80d8edf11d",
"message": "Merge pull request #6 from Spaceghost/patch-1\n\nNew line at end of file.",
"tree": {
"sha": "b4eecafa9be2f2006ce1b709d6857b07069b4608",
"url": "https://api.github.com/repos/octocat/Hello-World/git/trees/b4eecafa9be2f2006ce1b709d6857b07069b4608"
},
"committer": {
"name": "The Octocat",
"date": "2012-03-06T15:06:50-08:00",
"email": "octocat@nowhere.com"
},
"verification": {
"verified": false,
"reason": "unsigned",
"signature": null,
"payload": null
},
"comment_count": 0
},
"author": {
"gravatar_id": "",
"avatar_url": "https://secure.gravatar.com/avatar/7ad39074b0584bc555d0417ae3e7d974?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png",
"url": "https://api.github.com/users/octocat",
"id": 583231,
"login": "octocat",
"node_id": "MDQ6VXNlcjE=",
"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
},
"parents": [
{
"sha": "553c2077f0edc3d5dc5d17262f6aa498e69d6f8e",
"url": "https://api.github.com/repos/octocat/Hello-World/commits/553c2077f0edc3d5dc5d17262f6aa498e69d6f8e"
},
{
"sha": "762941318ee16e59dabbacb1b4049eec22f0d303",
"url": "https://api.github.com/repos/octocat/Hello-World/commits/762941318ee16e59dabbacb1b4049eec22f0d303"
}
],
"url": "https://api.github.com/repos/octocat/Hello-World/commits/7fd1a60b01f91b314f59955a4e4d4e80d8edf11d",
"committer": {
"gravatar_id": "",
"avatar_url": "https://secure.gravatar.com/avatar/7ad39074b0584bc555d0417ae3e7d974?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png",
"url": "https://api.github.com/users/octocat",
"id": 583231,
"login": "octocat",
"node_id": "MDQ6VXNlcjE=",
"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
},
"html_url": "https://github.com/octocat/Hello-World/commit/6dcb09b5b57875f334f61aebed695e2e4193db5e",
"comments_url": "https://api.github.com/repos/octocat/Hello-World/commits/6dcb09b5b57875f334f61aebed695e2e4193db5e/comments"
},
"_links": {
"html": "https://github.com/octocat/Hello-World/tree/master",
"self": "https://api.github.com/repos/octocat/Hello-World/branches/master"
},
"protected": true,
"protection": {
"required_status_checks": {
"enforcement_level": "non_admins",
"contexts": [
"ci-test",
"linter"
]
}
},
"protection_url": "https://api.github.com/repos/octocat/hello-world/branches/master/protection"
}
Forbidden
Status: 403 Forbidden
Resource not found
Status: 404 Not Found
Validation failed
Status: 422 Unprocessable Entity
Notes
Sync a fork branch with the upstream repository
Sync a branch of a forked repository to keep it up-to-date with the upstream repository.
post /repos/{owner}/{repo}/merge-upstream
Parameters
| Name | Type | In | Description |
|---|---|---|---|
accept |
string | header |
Setting to
|
owner |
string | path | |
repo |
string | path | |
branch |
string | body |
Required. The name of the branch which should be updated to match upstream. |
Code samples
Shell
curl \
-X POST \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/octocat/hello-world/merge-upstream \
-d '{"branch":"branch"}'JavaScript (@octokit/core.js)
await octokit.request('POST /repos/{owner}/{repo}/merge-upstream', {
owner: 'octocat',
repo: 'hello-world',
branch: 'branch'
})
The branch has been successfully synced with the upstream repository
Status: 200 OK
{
"message": "Successfully fetched and fast-forwarded from upstream defunkt:main",
"merge_type": "fast-forward",
"base_branch": "defunkt:main"
}
The branch could not be synced because of a merge conflict
Status: 409 Conflict
The branch could not be synced for some other reason
Status: 422 Unprocessable Entity
Notes
post /repos/{owner}/{repo}/merges
Parameters
| Name | Type | In | Description |
|---|---|---|---|
accept |
string | header |
Setting to
|
owner |
string | path | |
repo |
string | path | |
base |
string | body |
Required. The name of the base branch that the head will be merged into. |
head |
string | body |
Required. The head to merge. This can be a branch name or a commit SHA1. |
commit_message |
string | body |
Commit message to use for the merge commit. If omitted, a default message will be used. |
Code samples
Shell
curl \
-X POST \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/octocat/hello-world/merges \
-d '{"base":"base","head":"head"}'JavaScript (@octokit/core.js)
await octokit.request('POST /repos/{owner}/{repo}/merges', {
owner: 'octocat',
repo: 'hello-world',
base: 'base',
head: 'head'
})
Successful Response (The resulting merge commit)
Status: 201 Created
{
"url": "https://api.github.com/repos/octocat/Hello-World/commits/6dcb09b5b57875f334f61aebed695e2e4193db5e",
"sha": "6dcb09b5b57875f334f61aebed695e2e4193db5e",
"node_id": "MDY6Q29tbWl0NmRjYjA5YjViNTc4NzVmMzM0ZjYxYWViZWQ2OTVlMmU0MTkzZGI1ZQ==",
"html_url": "https://github.com/octocat/Hello-World/commit/6dcb09b5b57875f334f61aebed695e2e4193db5e",
"comments_url": "https://api.github.com/repos/octocat/Hello-World/commits/6dcb09b5b57875f334f61aebed695e2e4193db5e/comments",
"commit": {
"url": "https://api.github.com/repos/octocat/Hello-World/git/commits/6dcb09b5b57875f334f61aebed695e2e4193db5e",
"author": {
"name": "Monalisa Octocat",
"email": "mona@github.com",
"date": "2011-04-14T16:00:49Z"
},
"committer": {
"name": "Monalisa Octocat",
"email": "mona@github.com",
"date": "2011-04-14T16:00:49Z"
},
"message": "Fix all the bugs",
"tree": {
"url": "https://api.github.com/repos/octocat/Hello-World/tree/6dcb09b5b57875f334f61aebed695e2e4193db5e",
"sha": "6dcb09b5b57875f334f61aebed695e2e4193db5e"
},
"comment_count": 0,
"verification": {
"verified": false,
"reason": "unsigned",
"signature": null,
"payload": null
}
},
"author": {
"login": "octocat",
"id": 1,
"node_id": "MDQ6VXNlcjE=",
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
"gravatar_id": "",
"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": false
},
"committer": {
"login": "octocat",
"id": 1,
"node_id": "MDQ6VXNlcjE=",
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
"gravatar_id": "",
"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": false
},
"parents": [
{
"url": "https://api.github.com/repos/octocat/Hello-World/commits/6dcb09b5b57875f334f61aebed695e2e4193db5e",
"sha": "6dcb09b5b57875f334f61aebed695e2e4193db5e"
}
],
"stats": {
"additions": 104,
"deletions": 4,
"total": 108
},
"files": [
{
"filename": "file1.txt",
"additions": 10,
"deletions": 2,
"changes": 12,
"status": "modified",
"raw_url": "https://github.com/octocat/Hello-World/raw/7ca483543807a51b6079e54ac4cc392bc29ae284/file1.txt",
"blob_url": "https://github.com/octocat/Hello-World/blob/7ca483543807a51b6079e54ac4cc392bc29ae284/file1.txt",
"patch": "@@ -29,7 +29,7 @@\n....."
}
]
}
Response when already merged
Status: 204 No Content
Forbidden
Status: 403 Forbidden
Not Found when the base or head does not exist
Status: 404 Not Found
Conflict when there is a merge conflict
Status: 409 Conflict
Validation failed
Status: 422 Unprocessable Entity
Notes
Protected branches
Get 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 /repos/{owner}/{repo}/branches/{branch}/protection
Parameters
| Name | Type | In | Description |
|---|---|---|---|
accept |
string | header |
Setting to
|
owner |
string | path | |
repo |
string | path | |
branch |
string | path |
The name of the branch. |
Code samples
Shell
curl \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/octocat/hello-world/branches/BRANCH/protectionJavaScript (@octokit/core.js)
await octokit.request('GET /repos/{owner}/{repo}/branches/{branch}/protection', {
owner: 'octocat',
repo: 'hello-world',
branch: 'branch'
})
Response
Status: 200 OK
{
"url": "https://api.github.com/repos/octocat/Hello-World/branches/master/protection",
"required_status_checks": {
"url": "https://api.github.com/repos/octocat/Hello-World/branches/master/protection/required_status_checks",
"contexts": [
"continuous-integration/travis-ci"
],
"contexts_url": "https://api.github.com/repos/octocat/Hello-World/branches/master/protection/required_status_checks/contexts",
"enforcement_level": "non_admins"
},
"enforce_admins": {
"url": "https://api.github.com/repos/octocat/Hello-World/branches/master/protection/enforce_admins",
"enabled": true
},
"required_pull_request_reviews": {
"url": "https://api.github.com/repos/octocat/Hello-World/branches/master/protection/required_pull_request_reviews",
"dismissal_restrictions": {
"url": "https://api.github.com/repos/octocat/Hello-World/branches/master/protection/dismissal_restrictions",
"users_url": "https://api.github.com/repos/octocat/Hello-World/branches/master/protection/dismissal_restrictions/users",
"teams_url": "https://api.github.com/repos/octocat/Hello-World/branches/master/protection/dismissal_restrictions/teams",
"users": [
{
"login": "octocat",
"id": 1,
"node_id": "MDQ6VXNlcjE=",
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
"gravatar_id": "",
"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": false
}
],
"teams": [
{
"id": 1,
"node_id": "MDQ6VGVhbTE=",
"url": "https://api.github.com/teams/1",
"html_url": "https://github.com/orgs/github/teams/justice-league",
"name": "Justice League",
"slug": "justice-league",
"description": "A great team.",
"privacy": "closed",
"permission": "admin",
"members_url": "https://api.github.com/teams/1/members{/member}",
"repositories_url": "https://api.github.com/teams/1/repos",
"parent": null
}
]
},
"dismiss_stale_reviews": true,
"require_code_owner_reviews": true,
"required_approving_review_count": 2
},
"restrictions": {
"url": "https://api.github.com/repos/octocat/Hello-World/branches/master/protection/restrictions",
"users_url": "https://api.github.com/repos/octocat/Hello-World/branches/master/protection/restrictions/users",
"teams_url": "https://api.github.com/repos/octocat/Hello-World/branches/master/protection/restrictions/teams",
"apps_url": "https://api.github.com/repos/octocat/Hello-World/branches/master/protection/restrictions/teams",
"users": [
{
"login": "octocat",
"id": 1,
"node_id": "MDQ6VXNlcjE=",
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
"gravatar_id": "",
"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": false
}
],
"teams": [
{
"id": 1,
"node_id": "MDQ6VGVhbTE=",
"url": "https://api.github.com/teams/1",
"html_url": "https://github.com/orgs/github/teams/justice-league",
"name": "Justice League",
"slug": "justice-league",
"description": "A great team.",
"privacy": "closed",
"permission": "admin",
"members_url": "https://api.github.com/teams/1/members{/member}",
"repositories_url": "https://api.github.com/teams/1/repos",
"parent": null
}
],
"apps": [
{
"id": 1,
"slug": "octoapp",
"node_id": "MDExOkludGVncmF0aW9uMQ==",
"owner": {
"login": "github",
"id": 1,
"node_id": "MDEyOk9yZ2FuaXphdGlvbjE=",
"url": "https://api.github.com/orgs/github",
"repos_url": "https://api.github.com/orgs/github/repos",
"events_url": "https://api.github.com/orgs/github/events",
"hooks_url": "https://api.github.com/orgs/github/hooks",
"issues_url": "https://api.github.com/orgs/github/issues",
"members_url": "https://api.github.com/orgs/github/members{/member}",
"public_members_url": "https://api.github.com/orgs/github/public_members{/member}",
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
"description": "A great organization"
},
"name": "Octocat App",
"description": "",
"external_url": "https://example.com",
"html_url": "https://github.com/apps/octoapp",
"created_at": "2017-07-08T16:18:44-04:00",
"updated_at": "2017-07-08T16:18:44-04:00",
"permissions": {
"metadata": "read",
"contents": "read",
"issues": "write",
"single_file": "write"
},
"events": [
"push",
"pull_request"
]
}
]
},
"required_linear_history": {
"enabled": true
},
"allow_force_pushes": {
"enabled": true
},
"allow_deletions": {
"enabled": true
},
"required_conversation_resolution": {
"enabled": true
}
}
Resource not found
Status: 404 Not Found
Notes
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
Parameters
| Name | Type | In | Description | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
accept |
string | header |
Setting to
|
||||||||||||||||||||||||
owner |
string | path | |||||||||||||||||||||||||
repo |
string | path | |||||||||||||||||||||||||
branch |
string | path |
The name of the branch. |
||||||||||||||||||||||||
required_status_checks |
object or nullable | body |
Required. Require status checks to pass before merging. Set to |
||||||||||||||||||||||||
Properties of the
|
|||||||||||||||||||||||||||
| Name (Type) | Description |
|---|---|
strict (boolean)
|
Required. Require branches to be up to date before merging. |
contexts (array of strings)
|
Required. Deprecated: 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 |
checks (array of objects)
|
The list of status checks to require in order to merge into this branch. |
Properties of the
checks items
| Name (Type) | Description |
|---|---|
context (string)
|
Required. The name of the required check |
app_id (integer)
|
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. |
enforce_adminsRequired. 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_reviewsRequired. Require at least one approving review on a pull request, before merging. Set to null to disable.
Properties of the
required_pull_request_reviews object
| Name (Type) | Description |
|---|---|
dismissal_restrictions (object)
|
Specify which users and teams can dismiss pull request reviews. Pass an empty |
dismiss_stale_reviews (boolean)
|
Set to |
require_code_owner_reviews (boolean)
|
Blocks merging pull requests until code owners review them. |
required_approving_review_count (integer)
|
Specify the number of reviewers required to approve pull requests. Use a number between 1 and 6 or 0 to not require reviewers. |
bypass_pull_request_allowances (object or nullable)
|
Allow specific users or teams to bypass pull request requirements. Set to |
Properties of the
dismissal_restrictions object
| Name (Type) | Description |
|---|---|
users (array of strings)
|
The list of user |
teams (array of strings)
|
The list of team |
Properties of the
bypass_pull_request_allowances object
| Name (Type) | Description |
|---|---|
users (array of strings)
|
The list of user |
teams (array of strings)
|
The list of team |
restrictionsRequired. 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.
Properties of the
restrictions object
| Name (Type) | Description |
|---|---|
users (array of strings)
|
Required. The list of user |
teams (array of strings)
|
Required. The list of team |
apps (array of strings)
|
The list of app |
required_linear_historyEnforces 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_pushesPermits 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_deletionsAllows 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_resolutionRequires 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.
Code samples
Shell
curl \
-X PUT \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/octocat/hello-world/branches/BRANCH/protection \
-d '{"required_status_checks":{"strict":true,"contexts":["contexts"],"checks":[{"context":"context","app_id":42}]},"enforce_admins":true,"required_pull_request_reviews":{"dismissal_restrictions":{"users":["users"],"teams":["teams"]},"dismiss_stale_reviews":true,"require_code_owner_reviews":true,"required_approving_review_count":42,"bypass_pull_request_allowances":{"users":["users"],"teams":["teams"]}},"restrictions":{"users":["users"],"teams":["teams"],"apps":["apps"]}}'JavaScript (@octokit/core.js)
await octokit.request('PUT /repos/{owner}/{repo}/branches/{branch}/protection', {
owner: 'octocat',
repo: 'hello-world',
branch: 'branch',
required_status_checks: {
strict: true,
contexts: [
'contexts'
],
checks: [
{
context: 'context',
app_id: 42
}
]
},
enforce_admins: true,
required_pull_request_reviews: {
dismissal_restrictions: {
users: [
'users'
],
teams: [
'teams'
]
},
dismiss_stale_reviews: true,
require_code_owner_reviews: true,
required_approving_review_count: 42,
bypass_pull_request_allowances: {
users: [
'users'
],
teams: [
'teams'
]
}
},
restrictions: {
users: [
'users'
],
teams: [
'teams'
],
apps: [
'apps'
]
}
})
Response
Status: 200 OK
Forbidden
Status: 403 Forbidden
Resource not found
Status: 404 Not Found
Validation failed
Status: 422 Unprocessable Entity
Notes
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 /repos/{owner}/{repo}/branches/{branch}/protection
Parameters
| Name | Type | In | Description |
|---|---|---|---|
accept |
string | header |
Setting to
|
owner |
string | path | |
repo |
string | path | |
branch |
string | path |
The name of the branch. |
Code samples
Shell
curl \
-X DELETE \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/octocat/hello-world/branches/BRANCH/protectionJavaScript (@octokit/core.js)
await octokit.request('DELETE /repos/{owner}/{repo}/branches/{branch}/protection', {
owner: 'octocat',
repo: 'hello-world',
branch: 'branch'
})
Response
Status: 204 No Content
Forbidden
Status: 403 Forbidden
Notes
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 /repos/{owner}/{repo}/branches/{branch}/protection/enforce_admins
Parameters
| Name | Type | In | Description |
|---|---|---|---|
accept |
string | header |
Setting to
|
owner |
string | path | |
repo |
string | path | |
branch |
string | path |
The name of the branch. |
Code samples
Shell
curl \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/octocat/hello-world/branches/BRANCH/protection/enforce_adminsJavaScript (@octokit/core.js)
await octokit.request('GET /repos/{owner}/{repo}/branches/{branch}/protection/enforce_admins', {
owner: 'octocat',
repo: 'hello-world',
branch: 'branch'
})
Response
Status: 200 OK
{
"url": "https://api.github.com/repos/octocat/Hello-World/branches/master/protection/enforce_admins",
"enabled": true
}
Notes
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 /repos/{owner}/{repo}/branches/{branch}/protection/enforce_admins
Parameters
| Name | Type | In | Description |
|---|---|---|---|
accept |
string | header |
Setting to
|
owner |
string | path | |
repo |
string | path | |
branch |
string | path |
The name of the branch. |
Code samples
Shell
curl \
-X POST \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/octocat/hello-world/branches/BRANCH/protection/enforce_adminsJavaScript (@octokit/core.js)
await octokit.request('POST /repos/{owner}/{repo}/branches/{branch}/protection/enforce_admins', {
owner: 'octocat',
repo: 'hello-world',
branch: 'branch'
})
Response
Status: 200 OK
{
"url": "https://api.github.com/repos/octocat/Hello-World/branches/master/protection/enforce_admins",
"enabled": true
}
Notes
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 /repos/{owner}/{repo}/branches/{branch}/protection/enforce_admins
Parameters
| Name | Type | In | Description |
|---|---|---|---|
accept |
string | header |
Setting to
|
owner |
string | path | |
repo |
string | path | |
branch |
string | path |
The name of the branch. |
Code samples
Shell
curl \
-X DELETE \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/octocat/hello-world/branches/BRANCH/protection/enforce_adminsJavaScript (@octokit/core.js)
await octokit.request('DELETE /repos/{owner}/{repo}/branches/{branch}/protection/enforce_admins', {
owner: 'octocat',
repo: 'hello-world',
branch: 'branch'
})
Response
Status: 204 No Content
Resource not found
Status: 404 Not Found
Notes
Get pull request review 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 /repos/{owner}/{repo}/branches/{branch}/protection/required_pull_request_reviews
Parameters
| Name | Type | In | Description |
|---|---|---|---|
accept |
string | header |
Setting to
|
owner |
string | path | |
repo |
string | path | |
branch |
string | path |
The name of the branch. |
Code samples
Shell
curl \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/octocat/hello-world/branches/BRANCH/protection/required_pull_request_reviewsJavaScript (@octokit/core.js)
await octokit.request('GET /repos/{owner}/{repo}/branches/{branch}/protection/required_pull_request_reviews', {
owner: 'octocat',
repo: 'hello-world',
branch: 'branch'
})
Response
Status: 200 OK
{
"url": "https://api.github.com/repos/octocat/Hello-World/branches/master/protection/required_pull_request_reviews",
"dismissal_restrictions": {
"url": "https://api.github.com/repos/octocat/Hello-World/branches/master/protection/dismissal_restrictions",
"users_url": "https://api.github.com/repos/octocat/Hello-World/branches/master/protection/dismissal_restrictions/users",
"teams_url": "https://api.github.com/repos/octocat/Hello-World/branches/master/protection/dismissal_restrictions/teams",
"users": [
{
"login": "octocat",
"id": 1,
"node_id": "MDQ6VXNlcjE=",
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
"gravatar_id": "",
"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": false
}
],
"teams": [
{
"id": 1,
"node_id": "MDQ6VGVhbTE=",
"url": "https://api.github.com/teams/1",
"html_url": "https://github.com/orgs/github/teams/justice-league",
"name": "Justice League",
"slug": "justice-league",
"description": "A great team.",
"privacy": "closed",
"permission": "admin",
"members_url": "https://api.github.com/teams/1/members{/member}",
"repositories_url": "https://api.github.com/teams/1/repos",
"parent": null
}
]
},
"dismiss_stale_reviews": true,
"require_code_owner_reviews": true,
"required_approving_review_count": 2
}
Notes
Update pull request review 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.
Updating pull request review enforcement requires admin or owner permissions to the repository and branch protection to be enabled.
Note: Passing new arrays of users and teams replaces their previous values.
patch /repos/{owner}/{repo}/branches/{branch}/protection/required_pull_request_reviews
Parameters
| Name | Type | In | Description | ||||||
|---|---|---|---|---|---|---|---|---|---|
accept |
string | header |
Setting to
|
||||||
owner |
string | path | |||||||
repo |
string | path | |||||||
branch |
string | path |
The name of the branch. |
||||||
dismissal_restrictions |
object | body |
Specify which users and teams can dismiss pull request reviews. Pass an empty |
||||||
Properties of the
|
|||||||||
| Name (Type) | Description |
|---|---|
users (array of strings)
|
The list of user |
teams (array of strings)
|
The list of team |
dismiss_stale_reviewsSet to true if you want to automatically dismiss approving reviews when someone pushes a new commit.
require_code_owner_reviewsBlocks merging pull requests until code owners have reviewed.
required_approving_review_countSpecifies the number of reviewers required to approve pull requests. Use a number between 1 and 6 or 0 to not require reviewers.
bypass_pull_request_allowancesAllow specific users or teams to bypass pull request requirements. Set to null to disable.
Properties of the
bypass_pull_request_allowances object
| Name (Type) | Description |
|---|---|
users (array of strings)
|
The list of user |
teams (array of strings)
|
The list of team |
Code samples
Shell
curl \
-X PATCH \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/octocat/hello-world/branches/BRANCH/protection/required_pull_request_reviews \
-d '{"dismissal_restrictions":{"users":["users"],"teams":["teams"]}}'JavaScript (@octokit/core.js)
await octokit.request('PATCH /repos/{owner}/{repo}/branches/{branch}/protection/required_pull_request_reviews', {
owner: 'octocat',
repo: 'hello-world',
branch: 'branch',
dismissal_restrictions: {
users: [
'users'
],
teams: [
'teams'
]
}
})
Response
Status: 200 OK
{
"url": "https://api.github.com/repos/octocat/Hello-World/branches/master/protection/required_pull_request_reviews",
"dismissal_restrictions": {
"url": "https://api.github.com/repos/octocat/Hello-World/branches/master/protection/dismissal_restrictions",
"users_url": "https://api.github.com/repos/octocat/Hello-World/branches/master/protection/dismissal_restrictions/users",
"teams_url": "https://api.github.com/repos/octocat/Hello-World/branches/master/protection/dismissal_restrictions/teams",
"users": [
{
"login": "octocat",
"id": 1,
"node_id": "MDQ6VXNlcjE=",
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
"gravatar_id": "",
"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": false
}
],
"teams": [
{
"id": 1,
"node_id": "MDQ6VGVhbTE=",
"url": "https://api.github.com/teams/1",
"html_url": "https://github.com/orgs/github/teams/justice-league",
"name": "Justice League",
"slug": "justice-league",
"description": "A great team.",
"privacy": "closed",
"permission": "admin",
"members_url": "https://api.github.com/teams/1/members{/member}",
"repositories_url": "https://api.github.com/teams/1/repos",
"parent": null
}
]
},
"dismiss_stale_reviews": true,
"require_code_owner_reviews": true,
"required_approving_review_count": 2
}
Validation failed
Status: 422 Unprocessable Entity
Notes
Delete pull request review 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 /repos/{owner}/{repo}/branches/{branch}/protection/required_pull_request_reviews
Parameters
| Name | Type | In | Description |
|---|---|---|---|
accept |
string | header |
Setting to
|
owner |
string | path | |
repo |
string | path | |
branch |
string | path |
The name of the branch. |
Code samples
Shell
curl \
-X DELETE \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/octocat/hello-world/branches/BRANCH/protection/required_pull_request_reviewsJavaScript (@octokit/core.js)
await octokit.request('DELETE /repos/{owner}/{repo}/branches/{branch}/protection/required_pull_request_reviews', {
owner: 'octocat',
repo: 'hello-world',
branch: 'branch'
})
Response
Status: 204 No Content
Resource not found
Status: 404 Not Found
Notes
Get commit signature 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.
When authenticated with admin or owner permissions to the repository, you can use this endpoint to check whether a branch requires signed commits. An enabled status of true indicates you must sign commits on this branch. For more information, see Signing commits with GPG in GitHub Help.
Note: You must enable branch protection to require signed commits.
get /repos/{owner}/{repo}/branches/{branch}/protection/required_signatures
Parameters
| Name | Type | In | Description |
|---|---|---|---|
accept |
string | header |
Setting to
|
owner |
string | path | |
repo |
string | path | |
branch |
string | path |
The name of the branch. |
Code samples
Shell
curl \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/octocat/hello-world/branches/BRANCH/protection/required_signaturesJavaScript (@octokit/core.js)
await octokit.request('GET /repos/{owner}/{repo}/branches/{branch}/protection/required_signatures', {
owner: 'octocat',
repo: 'hello-world',
branch: 'branch'
})
Response
Status: 200 OK
{
"url": "https://api.github.com/repos/octocat/Hello-World/branches/master/protection/required_signatures",
"enabled": true
}
Resource not found
Status: 404 Not Found
Notes
Create commit signature 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.
When authenticated with admin or owner permissions to the repository, you can use this endpoint to require signed commits on a branch. You must enable branch protection to require signed commits.
post /repos/{owner}/{repo}/branches/{branch}/protection/required_signatures
Parameters
| Name | Type | In | Description |
|---|---|---|---|
accept |
string | header |
Setting to
|
owner |
string | path | |
repo |
string | path | |
branch |
string | path |
The name of the branch. |
Code samples
Shell
curl \
-X POST \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/octocat/hello-world/branches/BRANCH/protection/required_signaturesJavaScript (@octokit/core.js)
await octokit.request('POST /repos/{owner}/{repo}/branches/{branch}/protection/required_signatures', {
owner: 'octocat',
repo: 'hello-world',
branch: 'branch'
})
Response
Status: 200 OK
{
"url": "https://api.github.com/repos/octocat/Hello-World/branches/master/protection/required_signatures",
"enabled": true
}
Resource not found
Status: 404 Not Found
Notes
Delete commit signature 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.
When authenticated with admin or owner permissions to the repository, you can use this endpoint to disable required signed commits on a branch. You must enable branch protection to require signed commits.
delete /repos/{owner}/{repo}/branches/{branch}/protection/required_signatures
Parameters
| Name | Type | In | Description |
|---|---|---|---|
accept |
string | header |
Setting to
|
owner |
string | path | |
repo |
string | path | |
branch |
string | path |
The name of the branch. |
Code samples
Shell
curl \
-X DELETE \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/octocat/hello-world/branches/BRANCH/protection/required_signaturesJavaScript (@octokit/core.js)
await octokit.request('DELETE /repos/{owner}/{repo}/branches/{branch}/protection/required_signatures', {
owner: 'octocat',
repo: 'hello-world',
branch: 'branch'
})
Response
Status: 204 No Content
Resource not found
Status: 404 Not Found
Notes
Get status checks 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 /repos/{owner}/{repo}/branches/{branch}/protection/required_status_checks
Parameters
| Name | Type | In | Description |
|---|---|---|---|
accept |
string | header |
Setting to
|
owner |
string | path | |
repo |
string | path | |
branch |
string | path |
The name of the branch. |
Code samples
Shell
curl \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/octocat/hello-world/branches/BRANCH/protection/required_status_checksJavaScript (@octokit/core.js)
await octokit.request('GET /repos/{owner}/{repo}/branches/{branch}/protection/required_status_checks', {
owner: 'octocat',
repo: 'hello-world',
branch: 'branch'
})
Response
Status: 200 OK
{
"url": "https://api.github.com/repos/octocat/Hello-World/branches/master/protection/required_status_checks",
"strict": true,
"contexts": [
"continuous-integration/travis-ci"
],
"contexts_url": "https://api.github.com/repos/octocat/Hello-World/branches/master/protection/required_status_checks/contexts"
}
Resource not found
Status: 404 Not Found
Notes
Update status check 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.
Updating required status checks requires admin or owner permissions to the repository and branch protection to be enabled.
patch /repos/{owner}/{repo}/branches/{branch}/protection/required_status_checks
Parameters
| Name | Type | In | Description | ||||||
|---|---|---|---|---|---|---|---|---|---|
accept |
string | header |
Setting to
|
||||||
owner |
string | path | |||||||
repo |
string | path | |||||||
branch |
string | path |
The name of the branch. |
||||||
strict |
boolean | body |
Require branches to be up to date before merging. |
||||||
contexts |
array of strings | body |
Deprecated: 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 |
||||||
checks |
array of objects | body |
The list of status checks to require in order to merge into this branch. |
||||||
Properties of the
|
|||||||||
| Name (Type) | Description |
|---|---|
context (string)
|
Required. The name of the required check |
app_id (integer)
|
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. |
Code samples
Shell
curl \
-X PATCH \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/octocat/hello-world/branches/BRANCH/protection/required_status_checks \
-d '{"strict":true}'JavaScript (@octokit/core.js)
await octokit.request('PATCH /repos/{owner}/{repo}/branches/{branch}/protection/required_status_checks', {
owner: 'octocat',
repo: 'hello-world',
branch: 'branch',
strict: true
})
Response
Status: 200 OK
{
"url": "https://api.github.com/repos/octocat/Hello-World/branches/master/protection/required_status_checks",
"strict": true,
"contexts": [
"continuous-integration/travis-ci"
],
"contexts_url": "https://api.github.com/repos/octocat/Hello-World/branches/master/protection/required_status_checks/contexts"
}
Resource not found
Status: 404 Not Found
Validation failed
Status: 422 Unprocessable Entity
Notes
Remove status check 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 /repos/{owner}/{repo}/branches/{branch}/protection/required_status_checks
Parameters
| Name | Type | In | Description |
|---|---|---|---|
accept |
string | header |
Setting to
|
owner |
string | path | |
repo |
string | path | |
branch |
string | path |
The name of the branch. |
Code samples
Shell
curl \
-X DELETE \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/octocat/hello-world/branches/BRANCH/protection/required_status_checksJavaScript (@octokit/core.js)
await octokit.request('DELETE /repos/{owner}/{repo}/branches/{branch}/protection/required_status_checks', {
owner: 'octocat',
repo: 'hello-world',
branch: 'branch'
})
Response
Status: 204 No Content
Notes
Get all status check contexts
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 /repos/{owner}/{repo}/branches/{branch}/protection/required_status_checks/contexts
Parameters
| Name | Type | In | Description |
|---|---|---|---|
accept |
string | header |
Setting to
|
owner |
string | path | |
repo |
string | path | |
branch |
string | path |
The name of the branch. |
Code samples
Shell
curl \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/octocat/hello-world/branches/BRANCH/protection/required_status_checks/contextsJavaScript (@octokit/core.js)
await octokit.request('GET /repos/{owner}/{repo}/branches/{branch}/protection/required_status_checks/contexts', {
owner: 'octocat',
repo: 'hello-world',
branch: 'branch'
})
Response
Status: 200 OK
[
"continuous-integration/travis-ci"
]
Resource not found
Status: 404 Not Found
Notes
Add status check contexts
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.
post /repos/{owner}/{repo}/branches/{branch}/protection/required_status_checks/contexts
Parameters
| Name | Type | In | Description |
|---|---|---|---|
accept |
string | header |
Setting to
|
owner |
string | path | |
repo |
string | path | |
branch |
string | path |
The name of the branch. |
contexts |
array of strings | body |
Required. contexts parameter |
Code samples
Shell
curl \
-X POST \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/octocat/hello-world/branches/BRANCH/protection/required_status_checks/contextsJavaScript (@octokit/core.js)
await octokit.request('POST /repos/{owner}/{repo}/branches/{branch}/protection/required_status_checks/contexts', {
owner: 'octocat',
repo: 'hello-world',
branch: 'branch'
})
Response
Status: 200 OK
[
"continuous-integration/travis-ci",
"continuous-integration/jenkins"
]
Forbidden
Status: 403 Forbidden
Resource not found
Status: 404 Not Found
Validation failed
Status: 422 Unprocessable Entity
Notes
Set status check contexts
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.
put /repos/{owner}/{repo}/branches/{branch}/protection/required_status_checks/contexts
Parameters
| Name | Type | In | Description |
|---|---|---|---|
accept |
string | header |
Setting to
|
owner |
string | path | |
repo |
string | path | |
branch |
string | path |
The name of the branch. |
contexts |
array of strings | body |
Required. contexts parameter |
Code samples
Shell
curl \
-X PUT \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/octocat/hello-world/branches/BRANCH/protection/required_status_checks/contextsJavaScript (@octokit/core.js)
await octokit.request('PUT /repos/{owner}/{repo}/branches/{branch}/protection/required_status_checks/contexts', {
owner: 'octocat',
repo: 'hello-world',
branch: 'branch'
})
Response
Status: 200 OK
[
"continuous-integration/travis-ci"
]
Resource not found
Status: 404 Not Found
Validation failed
Status: 422 Unprocessable Entity
Notes
Remove status check contexts
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 /repos/{owner}/{repo}/branches/{branch}/protection/required_status_checks/contexts
Parameters
| Name | Type | In | Description |
|---|---|---|---|
accept |
string | header |
Setting to
|
owner |
string | path | |
repo |
string | path | |
branch |
string | path |
The name of the branch. |
contexts |
array of strings | body |
Required. contexts parameter |
Code samples
Shell
curl \
-X DELETE \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/octocat/hello-world/branches/BRANCH/protection/required_status_checks/contextsJavaScript (@octokit/core.js)
await octokit.request('DELETE /repos/{owner}/{repo}/branches/{branch}/protection/required_status_checks/contexts', {
owner: 'octocat',
repo: 'hello-world',
branch: 'branch'
})
Response
Status: 200 OK
[
"continuous-integration/travis-ci"
]
Resource not found
Status: 404 Not Found
Validation failed
Status: 422 Unprocessable Entity
Notes
Get access restrictions
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.
Lists who has access to this protected branch.
Note: Users, apps, and teams restrictions are only available for organization-owned repositories.
get /repos/{owner}/{repo}/branches/{branch}/protection/restrictions
Parameters
| Name | Type | In | Description |
|---|---|---|---|
accept |
string | header |
Setting to
|
owner |
string | path | |
repo |
string | path | |
branch |
string | path |
The name of the branch. |
Code samples
Shell
curl \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/octocat/hello-world/branches/BRANCH/protection/restrictionsJavaScript (@octokit/core.js)
await octokit.request('GET /repos/{owner}/{repo}/branches/{branch}/protection/restrictions', {
owner: 'octocat',
repo: 'hello-world',
branch: 'branch'
})
Response
Status: 200 OK
{
"url": "https://api.github.com/repos/octocat/Hello-World/branches/master/protection/restrictions",
"users_url": "https://api.github.com/repos/octocat/Hello-World/branches/master/protection/restrictions/users",
"teams_url": "https://api.github.com/repos/octocat/Hello-World/branches/master/protection/restrictions/teams",
"apps_url": "https://api.github.com/repos/octocat/Hello-World/branches/master/protection/restrictions/teams",
"users": [
{
"login": "octocat",
"id": 1,
"node_id": "MDQ6VXNlcjE=",
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
"gravatar_id": "",
"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": false
}
],
"teams": [
{
"id": 1,
"node_id": "MDQ6VGVhbTE=",
"url": "https://api.github.com/teams/1",
"html_url": "https://github.com/orgs/github/teams/justice-league",
"name": "Justice League",
"slug": "justice-league",
"description": "A great team.",
"privacy": "closed",
"permission": "admin",
"members_url": "https://api.github.com/teams/1/members{/member}",
"repositories_url": "https://api.github.com/teams/1/repos",
"parent": null
}
],
"apps": [
{
"id": 1,
"slug": "octoapp",
"node_id": "MDExOkludGVncmF0aW9uMQ==",
"owner": {
"login": "github",
"id": 1,
"node_id": "MDEyOk9yZ2FuaXphdGlvbjE=",
"url": "https://api.github.com/orgs/github",
"repos_url": "https://api.github.com/orgs/github/repos",
"events_url": "https://api.github.com/orgs/github/events",
"hooks_url": "https://api.github.com/orgs/github/hooks",
"issues_url": "https://api.github.com/orgs/github/issues",
"members_url": "https://api.github.com/orgs/github/members{/member}",
"public_members_url": "https://api.github.com/orgs/github/public_members{/member}",
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
"description": "A great organization"
},
"name": "Octocat App",
"description": "",
"external_url": "https://example.com",
"html_url": "https://github.com/apps/octoapp",
"created_at": "2017-07-08T16:18:44-04:00",
"updated_at": "2017-07-08T16:18:44-04:00",
"permissions": {
"metadata": "read",
"contents": "read",
"issues": "write",
"single_file": "write"
},
"events": [
"push",
"pull_request"
]
}
]
}
Resource not found
Status: 404 Not Found
Notes
Delete access restrictions
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.
Disables the ability to restrict who can push to this branch.
delete /repos/{owner}/{repo}/branches/{branch}/protection/restrictions
Parameters
| Name | Type | In | Description |
|---|---|---|---|
accept |
string | header |
Setting to
|
owner |
string | path | |
repo |
string | path | |
branch |
string | path |
The name of the branch. |
Code samples
Shell
curl \
-X DELETE \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/octocat/hello-world/branches/BRANCH/protection/restrictionsJavaScript (@octokit/core.js)
await octokit.request('DELETE /repos/{owner}/{repo}/branches/{branch}/protection/restrictions', {
owner: 'octocat',
repo: 'hello-world',
branch: 'branch'
})
Response
Status: 204 No Content
Notes
Get apps with access to the protected branch
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.
Lists the GitHub Apps that have push access to this branch. Only installed GitHub Apps with write access to the contents permission can be added as authorized actors on a protected branch.
get /repos/{owner}/{repo}/branches/{branch}/protection/restrictions/apps
Parameters
| Name | Type | In | Description |
|---|---|---|---|
accept |
string | header |
Setting to
|
owner |
string | path | |
repo |
string | path | |
branch |
string | path |
The name of the branch. |
Code samples
Shell
curl \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/octocat/hello-world/branches/BRANCH/protection/restrictions/appsJavaScript (@octokit/core.js)
await octokit.request('GET /repos/{owner}/{repo}/branches/{branch}/protection/restrictions/apps', {
owner: 'octocat',
repo: 'hello-world',
branch: 'branch'
})
Response
Status: 200 OK
[
{
"id": 1,
"slug": "octoapp",
"node_id": "MDExOkludGVncmF0aW9uMQ==",
"owner": {
"login": "github",
"id": 1,
"node_id": "MDEyOk9yZ2FuaXphdGlvbjE=",
"url": "https://api.github.com/orgs/github",
"repos_url": "https://api.github.com/orgs/github/repos",
"events_url": "https://api.github.com/orgs/github/events",
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
"gravatar_id": "",
"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",
"received_events_url": "https://api.github.com/users/octocat/received_events",
"type": "User",
"site_admin": true
},
"name": "Octocat App",
"description": "",
"external_url": "https://example.com",
"html_url": "https://github.com/apps/octoapp",
"created_at": "2017-07-08T16:18:44-04:00",
"updated_at": "2017-07-08T16:18:44-04:00",
"permissions": {
"metadata": "read",
"contents": "read",
"issues": "write",
"single_file": "write"
},
"events": [
"push",
"pull_request"
]
}
]
Resource not found
Status: 404 Not Found
Notes
Add app access restrictions
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.
Grants the specified apps push access for this branch. Only installed GitHub Apps with write access to the contents permission can be added as authorized actors on a protected branch.
| Type | Description |
|---|---|
array | The GitHub Apps that have push access to this branch. Use the app's slug. Note: The list of users, apps, and teams in total is limited to 100 items. |
post /repos/{owner}/{repo}/branches/{branch}/protection/restrictions/apps
Parameters
| Name | Type | In | Description |
|---|---|---|---|
accept |
string | header |
Setting to
|
owner |
string | path | |
repo |
string | path | |
branch |
string | path |
The name of the branch. |
apps |
array of strings | body |
Required. apps parameter |
Code samples
Shell
curl \
-X POST \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/octocat/hello-world/branches/BRANCH/protection/restrictions/appsJavaScript (@octokit/core.js)
await octokit.request('POST /repos/{owner}/{repo}/branches/{branch}/protection/restrictions/apps', {
owner: 'octocat',
repo: 'hello-world',
branch: 'branch'
})
Response
Status: 200 OK
[
{
"id": 1,
"slug": "octoapp",
"node_id": "MDExOkludGVncmF0aW9uMQ==",
"owner": {
"login": "github",
"id": 1,
"node_id": "MDEyOk9yZ2FuaXphdGlvbjE=",
"url": "https://api.github.com/orgs/github",
"repos_url": "https://api.github.com/orgs/github/repos",
"events_url": "https://api.github.com/orgs/github/events",
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
"gravatar_id": "",
"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",
"received_events_url": "https://api.github.com/users/octocat/received_events",
"type": "User",
"site_admin": true
},
"name": "Octocat App",
"description": "",
"external_url": "https://example.com",
"html_url": "https://github.com/apps/octoapp",
"created_at": "2017-07-08T16:18:44-04:00",
"updated_at": "2017-07-08T16:18:44-04:00",
"permissions": {
"metadata": "read",
"contents": "read",
"issues": "write",
"single_file": "write"
},
"events": [
"push",
"pull_request"
]
}
]
Validation failed
Status: 422 Unprocessable Entity
Notes
Set app access restrictions
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.
Replaces the list of apps that have push access to this branch. This removes all apps that previously had push access and grants push access to the new list of apps. Only installed GitHub Apps with write access to the contents permission can be added as authorized actors on a protected branch.
| Type | Description |
|---|---|
array | The GitHub Apps that have push access to this branch. Use the app's slug. Note: The list of users, apps, and teams in total is limited to 100 items. |
put /repos/{owner}/{repo}/branches/{branch}/protection/restrictions/apps
Parameters
| Name | Type | In | Description |
|---|---|---|---|
accept |
string | header |
Setting to
|
owner |
string | path | |
repo |
string | path | |
branch |
string | path |
The name of the branch. |
apps |
array of strings | body |
Required. apps parameter |
Code samples
Shell
curl \
-X PUT \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/octocat/hello-world/branches/BRANCH/protection/restrictions/appsJavaScript (@octokit/core.js)
await octokit.request('PUT /repos/{owner}/{repo}/branches/{branch}/protection/restrictions/apps', {
owner: 'octocat',
repo: 'hello-world',
branch: 'branch'
})
Response
Status: 200 OK
[
{
"id": 1,
"slug": "octoapp",
"node_id": "MDExOkludGVncmF0aW9uMQ==",
"owner": {
"login": "github",
"id": 1,
"node_id": "MDEyOk9yZ2FuaXphdGlvbjE=",
"url": "https://api.github.com/orgs/github",
"repos_url": "https://api.github.com/orgs/github/repos",
"events_url": "https://api.github.com/orgs/github/events",
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
"gravatar_id": "",
"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",
"received_events_url": "https://api.github.com/users/octocat/received_events",
"type": "User",
"site_admin": true
},
"name": "Octocat App",
"description": "",
"external_url": "https://example.com",
"html_url": "https://github.com/apps/octoapp",
"created_at": "2017-07-08T16:18:44-04:00",
"updated_at": "2017-07-08T16:18:44-04:00",
"permissions": {
"metadata": "read",
"contents": "read",
"issues": "write",
"single_file": "write"
},
"events": [
"push",
"pull_request"
]
}
]
Validation failed
Status: 422 Unprocessable Entity
Notes
Remove app access restrictions
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.
Removes the ability of an app to push to this branch. Only installed GitHub Apps with write access to the contents permission can be added as authorized actors on a protected branch.
| Type | Description |
|---|---|
array | The GitHub Apps that have push access to this branch. Use the app's slug. Note: The list of users, apps, and teams in total is limited to 100 items. |
delete /repos/{owner}/{repo}/branches/{branch}/protection/restrictions/apps
Parameters
| Name | Type | In | Description |
|---|---|---|---|
accept |
string | header |
Setting to
|
owner |
string | path | |
repo |
string | path | |
branch |
string | path |
The name of the branch. |
apps |
array of strings | body |
Required. apps parameter |
Code samples
Shell
curl \
-X DELETE \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/octocat/hello-world/branches/BRANCH/protection/restrictions/appsJavaScript (@octokit/core.js)
await octokit.request('DELETE /repos/{owner}/{repo}/branches/{branch}/protection/restrictions/apps', {
owner: 'octocat',
repo: 'hello-world',
branch: 'branch'
})
Response
Status: 200 OK
[
{
"id": 1,
"slug": "octoapp",
"node_id": "MDExOkludGVncmF0aW9uMQ==",
"owner": {
"login": "github",
"id": 1,
"node_id": "MDEyOk9yZ2FuaXphdGlvbjE=",
"url": "https://api.github.com/orgs/github",
"repos_url": "https://api.github.com/orgs/github/repos",
"events_url": "https://api.github.com/orgs/github/events",
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
"gravatar_id": "",
"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",
"received_events_url": "https://api.github.com/users/octocat/received_events",
"type": "User",
"site_admin": true
},
"name": "Octocat App",
"description": "",
"external_url": "https://example.com",
"html_url": "https://github.com/apps/octoapp",
"created_at": "2017-07-08T16:18:44-04:00",
"updated_at": "2017-07-08T16:18:44-04:00",
"permissions": {
"metadata": "read",
"contents": "read",
"issues": "write",
"single_file": "write"
},
"events": [
"push",
"pull_request"
]
}
]
Validation failed
Status: 422 Unprocessable Entity
Notes
Get teams with access to the protected branch
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.
Lists the teams who have push access to this branch. The list includes child teams.
get /repos/{owner}/{repo}/branches/{branch}/protection/restrictions/teams
Parameters
| Name | Type | In | Description |
|---|---|---|---|
accept |
string | header |
Setting to
|
owner |
string | path | |
repo |
string | path | |
branch |
string | path |
The name of the branch. |
Code samples
Shell
curl \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/octocat/hello-world/branches/BRANCH/protection/restrictions/teamsJavaScript (@octokit/core.js)
await octokit.request('GET /repos/{owner}/{repo}/branches/{branch}/protection/restrictions/teams', {
owner: 'octocat',
repo: 'hello-world',
branch: 'branch'
})
Response
Status: 200 OK
[
{
"id": 1,
"node_id": "MDQ6VGVhbTE=",
"url": "https://api.github.com/teams/1",
"html_url": "https://github.com/orgs/github/teams/justice-league",
"name": "Justice League",
"slug": "justice-league",
"description": "A great team.",
"privacy": "closed",
"permission": "admin",
"members_url": "https://api.github.com/teams/1/members{/member}",
"repositories_url": "https://api.github.com/teams/1/repos",
"parent": null
}
]
Resource not found
Status: 404 Not Found
Notes
Add team access restrictions
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.
Grants the specified teams push access for this branch. You can also give push access to child teams.
| Type | Description |
|---|---|
array | The teams that can have push access. Use the team's slug. Note: The list of users, apps, and teams in total is limited to 100 items. |
post /repos/{owner}/{repo}/branches/{branch}/protection/restrictions/teams
Parameters
| Name | Type | In | Description |
|---|---|---|---|
accept |
string | header |
Setting to
|
owner |
string | path | |
repo |
string | path | |
branch |
string | path |
The name of the branch. |
teams |
array of strings | body |
Required. teams parameter |
Code samples
Shell
curl \
-X POST \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/octocat/hello-world/branches/BRANCH/protection/restrictions/teamsJavaScript (@octokit/core.js)
await octokit.request('POST /repos/{owner}/{repo}/branches/{branch}/protection/restrictions/teams', {
owner: 'octocat',
repo: 'hello-world',
branch: 'branch'
})
Response
Status: 200 OK
[
{
"id": 1,
"node_id": "MDQ6VGVhbTE=",
"url": "https://api.github.com/teams/1",
"html_url": "https://github.com/orgs/github/teams/justice-league",
"name": "Justice League",
"slug": "justice-league",
"description": "A great team.",
"privacy": "closed",
"permission": "admin",
"members_url": "https://api.github.com/teams/1/members{/member}",
"repositories_url": "https://api.github.com/teams/1/repos",
"parent": null
}
]
Validation failed
Status: 422 Unprocessable Entity
Notes
Set team access restrictions
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.
Replaces the list of teams that have push access to this branch. This removes all teams that previously had push access and grants push access to the new list of teams. Team restrictions include child teams.
| Type | Description |
|---|---|
array | The teams that can have push access. Use the team's slug. Note: The list of users, apps, and teams in total is limited to 100 items. |
put /repos/{owner}/{repo}/branches/{branch}/protection/restrictions/teams
Parameters
| Name | Type | In | Description |
|---|---|---|---|
accept |
string | header |
Setting to
|
owner |
string | path | |
repo |
string | path | |
branch |
string | path |
The name of the branch. |
teams |
array of strings | body |
Required. teams parameter |
Code samples
Shell
curl \
-X PUT \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/octocat/hello-world/branches/BRANCH/protection/restrictions/teamsJavaScript (@octokit/core.js)
await octokit.request('PUT /repos/{owner}/{repo}/branches/{branch}/protection/restrictions/teams', {
owner: 'octocat',
repo: 'hello-world',
branch: 'branch'
})
Response
Status: 200 OK
[
{
"id": 1,
"node_id": "MDQ6VGVhbTE=",
"url": "https://api.github.com/teams/1",
"html_url": "https://github.com/orgs/github/teams/justice-league",
"name": "Justice League",
"slug": "justice-league",
"description": "A great team.",
"privacy": "closed",
"permission": "admin",
"members_url": "https://api.github.com/teams/1/members{/member}",
"repositories_url": "https://api.github.com/teams/1/repos",
"parent": null
}
]
Validation failed
Status: 422 Unprocessable Entity
Notes
Remove team access restrictions
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.
Removes the ability of a team to push to this branch. You can also remove push access for child teams.
| Type | Description |
|---|---|
array | Teams that should no longer have push access. Use the team's slug. Note: The list of users, apps, and teams in total is limited to 100 items. |
delete /repos/{owner}/{repo}/branches/{branch}/protection/restrictions/teams
Parameters
| Name | Type | In | Description |
|---|---|---|---|
accept |
string | header |
Setting to
|
owner |
string | path | |
repo |
string | path | |
branch |
string | path |
The name of the branch. |
teams |
array of strings | body |
Required. teams parameter |
Code samples
Shell
curl \
-X DELETE \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/octocat/hello-world/branches/BRANCH/protection/restrictions/teamsJavaScript (@octokit/core.js)
await octokit.request('DELETE /repos/{owner}/{repo}/branches/{branch}/protection/restrictions/teams', {
owner: 'octocat',
repo: 'hello-world',
branch: 'branch'
})
Response
Status: 200 OK
[
{
"id": 1,
"node_id": "MDQ6VGVhbTE=",
"url": "https://api.github.com/teams/1",
"html_url": "https://github.com/orgs/github/teams/justice-league",
"name": "Justice League",
"slug": "justice-league",
"description": "A great team.",
"privacy": "closed",
"permission": "admin",
"members_url": "https://api.github.com/teams/1/members{/member}",
"repositories_url": "https://api.github.com/teams/1/repos",
"parent": null
}
]
Validation failed
Status: 422 Unprocessable Entity
Notes
Get users with access to the protected branch
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.
Lists the people who have push access to this branch.
get /repos/{owner}/{repo}/branches/{branch}/protection/restrictions/users
Parameters
| Name | Type | In | Description |
|---|---|---|---|
accept |
string | header |
Setting to
|
owner |
string | path | |
repo |
string | path | |
branch |
string | path |
The name of the branch. |
Code samples
Shell
curl \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/octocat/hello-world/branches/BRANCH/protection/restrictions/usersJavaScript (@octokit/core.js)
await octokit.request('GET /repos/{owner}/{repo}/branches/{branch}/protection/restrictions/users', {
owner: 'octocat',
repo: 'hello-world',
branch: 'branch'
})
Response
Status: 200 OK
[
{
"login": "octocat",
"id": 1,
"node_id": "MDQ6VXNlcjE=",
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
"gravatar_id": "",
"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": false
}
]
Resource not found
Status: 404 Not Found
Notes
Add user access restrictions
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.
Grants the specified people push access for this branch.
| Type | Description |
|---|---|
array | Usernames for people who can have push access. Note: The list of users, apps, and teams in total is limited to 100 items. |
post /repos/{owner}/{repo}/branches/{branch}/protection/restrictions/users
Parameters
| Name | Type | In | Description |
|---|---|---|---|
accept |
string | header |
Setting to
|
owner |
string | path | |
repo |
string | path | |
branch |
string | path |
The name of the branch. |
users |
array of strings | body |
Required. users parameter |
Code samples
Shell
curl \
-X POST \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/octocat/hello-world/branches/BRANCH/protection/restrictions/usersJavaScript (@octokit/core.js)
await octokit.request('POST /repos/{owner}/{repo}/branches/{branch}/protection/restrictions/users', {
owner: 'octocat',
repo: 'hello-world',
branch: 'branch'
})
Response
Status: 200 OK
[
{
"login": "octocat",
"id": 1,
"node_id": "MDQ6VXNlcjE=",
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
"gravatar_id": "",
"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": false
}
]
Validation failed
Status: 422 Unprocessable Entity
Notes
Set user access restrictions
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.
Replaces the list of people that have push access to this branch. This removes all people that previously had push access and grants push access to the new list of people.
| Type | Description |
|---|---|
array | Usernames for people who can have push access. Note: The list of users, apps, and teams in total is limited to 100 items. |
put /repos/{owner}/{repo}/branches/{branch}/protection/restrictions/users
Parameters
| Name | Type | In | Description |
|---|---|---|---|
accept |
string | header |
Setting to
|
owner |
string | path | |
repo |
string | path | |
branch |
string | path |
The name of the branch. |
users |
array of strings | body |
Required. users parameter |
Code samples
Shell
curl \
-X PUT \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/octocat/hello-world/branches/BRANCH/protection/restrictions/usersJavaScript (@octokit/core.js)
await octokit.request('PUT /repos/{owner}/{repo}/branches/{branch}/protection/restrictions/users', {
owner: 'octocat',
repo: 'hello-world',
branch: 'branch'
})
Response
Status: 200 OK
[
{
"login": "octocat",
"id": 1,
"node_id": "MDQ6VXNlcjE=",
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
"gravatar_id": "",
"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": false
}
]
Validation failed
Status: 422 Unprocessable Entity
Notes
Remove user access restrictions
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.
Removes the ability of a user to push to this branch.
| Type | Description |
|---|---|
array | Usernames of the people who should no longer have push access. Note: The list of users, apps, and teams in total is limited to 100 items. |
delete /repos/{owner}/{repo}/branches/{branch}/protection/restrictions/users
Parameters
| Name | Type | In | Description |
|---|---|---|---|
accept |
string | header |
Setting to
|
owner |
string | path | |
repo |
string | path | |
branch |
string | path |
The name of the branch. |
users |
array of strings | body |
Required. users parameter |
Code samples
Shell
curl \
-X DELETE \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/octocat/hello-world/branches/BRANCH/protection/restrictions/usersJavaScript (@octokit/core.js)
await octokit.request('DELETE /repos/{owner}/{repo}/branches/{branch}/protection/restrictions/users', {
owner: 'octocat',
repo: 'hello-world',
branch: 'branch'
})
Response
Status: 200 OK
[
{
"login": "octocat",
"id": 1,
"node_id": "MDQ6VXNlcjE=",
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
"gravatar_id": "",
"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": false
}
]
Validation failed
Status: 422 Unprocessable Entity