# gh ruleset: View Repository Rulesets in CI

> gh ruleset lists, views, and checks the rulesets that apply to a branch. Reference for list, view, check, --json, and the permission errors in CI.

Source: https://latchkey.dev/learn/command-reference/gh-ruleset  
Updated: 2026-06-30

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 / Flag | What it does |
| --- | --- |
| list | List 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.

## Using this in CI

CI checkouts are shallow and detached by default, which changes the answer this command gives you. Commands that read history, branch names, or tags need the checkout configured for it.

```.github/workflows/ci.yml
- uses: actions/checkout@v4
  with:
    fetch-depth: 0   # history, tags, and git describe all need this

- run: |
    git rev-parse --is-shallow-repository   # expect false
    git rev-parse --abbrev-ref HEAD          # prints HEAD when detached
```

> `git rev-parse --abbrev-ref HEAD` returns the literal string `HEAD` on a detached checkout rather than a branch name. On GitHub Actions read `github.ref_name` instead; the git command cannot know what it was checked out for.

## FAQ

### gh ruleset: View Repository Rulesets in CI?

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.

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

---

Latchkey runs CI/CD that repairs its own failures. Agent entry points: https://latchkey.dev/agent.txt, https://latchkey.dev/openapi.json, https://latchkey.dev/llms.txt
