Skip to content
Latchkey

gh ruleset: View Repository Rulesets in CI

gh ruleset lists and inspects the repository rulesets that govern branch and tag protection.

Rulesets are the modern replacement for branch protection; gh ruleset shows which rules apply so automation knows what a push must satisfy.

What it does

gh ruleset groups subcommands for repository rulesets. gh ruleset list shows configured rulesets, gh ruleset view shows one in detail, and gh ruleset check reports which rulesets would apply to a given branch.

Common usage

Terminal
gh ruleset list
gh ruleset view 42
gh ruleset check main
gh ruleset list --json id,name,target

Flags

Subcommand / FlagWhat it does
listList rulesets for the repository or org
view <id>Show details of one ruleset
check <branch>Show rulesets that apply to a branch
-o, --org <name>Operate on organization-level rulesets
--json <fields>Output ruleset data as JSON
-R, --repo <owner/repo>Target a specific repository

In CI

Set GH_TOKEN and permissions: { contents: read } for repository rulesets; organization rulesets require a token with org admin scope, which the default GITHUB_TOKEN does not have. Use gh ruleset check <branch> to learn why a push or merge is being blocked.

Common errors in CI

"Resource not accessible by integration" means the token lacks scope, common when reading org rulesets with the default token. "gh: To use GitHub CLI in a GitHub Actions workflow, set the GH_TOKEN environment variable" means GH_TOKEN is unset. An empty list means no rulesets are configured at that level.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →