REST API endpoints for rules

Use the REST API to manage rulesets for repositories. Rulesets control how people can interact with selected branches and tags in a repository.

Note

Most endpoints use Authorization: Bearer <YOUR-TOKEN> and Accept: application/vnd.github+json headers, plus X-GitHub-Api-Version: 2026-03-10. Curl examples below omit these standard headers for brevity.

Get rules for a branch

GET /repos/{owner}/{repo}/rules/branches/{branch}

Returns all active rules that apply to the specified branch. The branch does not need to exist; rules that would apply
to a branch with that name will be returned. All active rules that apply will be returned, regardless of the level
at which they are configured (e.g. repository or organization). Rules in rulesets with "evaluate" or "disabled"
enforcement statuses are not returned.

Parameters

Headers

Path and query parameters

HTTP response status codes

Code examples

Example

Request:

curl -L \
  -X GET \
  https://api.github.com/repos/OWNER/REPO/rules/branches/BRANCH

Response schema (Status: 200):

Array of Repository Rule objects: one of:

Get all repository rulesets

GET /repos/{owner}/{repo}/rulesets

Get all the rulesets for a repository.

Parameters

Headers

Path and query parameters

HTTP response status codes

Code examples

Example

Request:

curl -L \
  -X GET \
  https://api.github.com/repos/OWNER/REPO/rulesets

Response schema (Status: 200):

Array of Repository ruleset:

Create a repository ruleset

POST /repos/{owner}/{repo}/rulesets

Create a ruleset for a repository.

Parameters

Headers

Path and query parameters

Body parameters

HTTP response status codes

Code examples

Example

Request:

curl -L \
  -X POST \
  https://api.github.com/repos/OWNER/REPO/rulesets \
  -d '{
  "name": "super cool ruleset",
  "target": "branch",
  "enforcement": "active",
  "bypass_actors": [
    {
      "actor_id": 234,
      "actor_type": "Team",
      "bypass_mode": "always"
    }
  ],
  "conditions": {
    "ref_name": {
      "include": [
        "refs/heads/main",
        "refs/heads/master"
      ],
      "exclude": [
        "refs/heads/dev*"
      ]
    }
  },
  "rules": [
    {
      "type": "commit_author_email_pattern",
      "parameters": {
        "operator": "contains",
        "pattern": "github"
      }
    }
  ]
}'

Response schema (Status: 201):

Get a repository ruleset

GET /repos/{owner}/{repo}/rulesets/{ruleset_id}

Get a ruleset for a repository.
Note: To prevent leaking sensitive information, the bypass_actors property is only returned if the user
making the API request has write access to the ruleset.

Parameters

Headers

Path and query parameters

HTTP response status codes

Code examples

Example

Request:

curl -L \
  -X GET \
  https://api.github.com/repos/OWNER/REPO/rulesets/RULESET_ID

Response schema (Status: 200):

Same response schema as Create a repository ruleset.

Update a repository ruleset

PUT /repos/{owner}/{repo}/rulesets/{ruleset_id}

Update a ruleset for a repository.

Parameters

Headers

Path and query parameters

Body parameters

HTTP response status codes

Code examples

Example

Request:

curl -L \
  -X PUT \
  https://api.github.com/repos/OWNER/REPO/rulesets/RULESET_ID \
  -d '{
  "name": "super cool ruleset",
  "target": "branch",
  "enforcement": "active",
  "bypass_actors": [
    {
      "actor_id": 234,
      "actor_type": "Team",
      "bypass_mode": "always"
    }
  ],
  "conditions": {
    "ref_name": {
      "include": [
        "refs/heads/main",
        "refs/heads/master"
      ],
      "exclude": [
        "refs/heads/dev*"
      ]
    }
  },
  "rules": [
    {
      "type": "commit_author_email_pattern",
      "parameters": {
        "operator": "contains",
        "pattern": "github"
      }
    }
  ]
}'

Response schema (Status: 200):

Same response schema as Create a repository ruleset.

Delete a repository ruleset

DELETE /repos/{owner}/{repo}/rulesets/{ruleset_id}

Delete a ruleset for a repository.

Parameters

Headers

Path and query parameters

HTTP response status codes

Code examples

Example

Request:

curl -L \
  -X DELETE \
  https://api.github.com/repos/OWNER/REPO/rulesets/RULESET_ID

Response schema (Status: 204):

Get repository ruleset history

GET /repos/{owner}/{repo}/rulesets/{ruleset_id}/history

Get the history of a repository ruleset.

Parameters

Headers

Path and query parameters

HTTP response status codes

Code examples

Example

Request:

curl -L \
  -X GET \
  https://api.github.com/repos/OWNER/REPO/rulesets/RULESET_ID/history

Response schema (Status: 200):

Array of Ruleset version:

Get repository ruleset version

GET /repos/{owner}/{repo}/rulesets/{ruleset_id}/history/{version_id}

Get a version of a repository ruleset.

Parameters

Headers

Path and query parameters

HTTP response status codes

Code examples

Example

Request:

curl -L \
  -X GET \
  https://api.github.com/repos/OWNER/REPO/rulesets/RULESET_ID/history/VERSION_ID

Response schema (Status: 200):