agentleFS
mir-ammir-am/skills-agents-ai-coding/skills/gh-protect-default-branch/SKILL.md

gh-protect-default-branch

Skill2 starsChanged 43 days agoMITView on GitHub

Protect the default branch from direct pushes so changes land only via pull requests

The file

We split this skill into the rules it gives an agent

9 rules. About 0 are common, 4 are distinctive, and 5 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈4

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 5

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Verify the protection was applied correctly

    line 15
  2. Distinctive:

    Use this skill when the user wants to protect the default branch from direct pushes so that changes can only be merged through pull …

    line 20
  3. Distinctive:

    Must be inside a git repo with a GitHub remote

    line 25
  4. Very specific:

    If gh not installed -> error: Error: GitHub CLI not found.

    line 27
  5. Very specific:

    If not authenticated -> error: Error: Not authenticated with GitHub.

    line 28
  6. Very specific:

    If not admin -> error: Error: Admin permissions required to set branch protection

    line 29
  7. Very specific:

    All three fields should be true.

    line 70
  8. Distinctive:

    Use this only when the user explicitly asks to remove protection.

    line 79
  9. Very specific:

    No GitHub remote -> Error: No GitHub remote found.

    line 100

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

What I do

  • Detect the repository's default branch automatically
  • Apply minimal branch protection: require a pull request before merging, block force pushes and deletions
  • Verify the protection was applied correctly
  • Optionally remove protection if the user asks

When to use me

Use this skill when the user wants to protect the default branch from direct pushes so that changes can only be merged through pull requests.

Prerequisites

  • GitHub CLI (gh) must be installed and authenticated
  • Must be inside a git repo with a GitHub remote
  • The authenticated user must have admin permissions on the repository
  • If gh not installed -> error: Error: GitHub CLI not found. Install: https://cli.github.com/
  • If not authenticated -> error: Error: Not authenticated with GitHub. Run: gh auth login
  • If not admin -> error: Error: Admin permissions required to set branch protection

Apply Protection Workflow

  1. Validate GitHub access
    gh auth status
  2. Detect default branch and repo
    gh repo view --json nameWithOwner,defaultBranchRef --jq '"\(.nameWithOwner) \(.defaultBranchRef.name)"'
    Parse the output to get OWNER/REPO and BRANCH.
  3. Apply minimal branch protection
    gh api -X PUT \
      -H "Accept: application/vnd.github+json" \
      "repos/{owner}/{repo}/branches/{branch}/protection" \
      --input - <<'EOF'
    {
      "required_status_checks": null,
      "enforce_admins": true,
      "required_pull_request_reviews": {
        "required_approving_review_count": 0
      },
      "restrictions": null,
      "allow_force_pushes": false,
      "allow_deletions": false
    }
    EOF
    Replace {owner}/{repo} and {branch} with the values from step 2.
  4. Verify protection
    gh api -H "Accept: application/vnd.github+json" \
      "repos/{owner}/{repo}/branches/{branch}/protection" \
      --jq '{pr_required: (.required_pull_request_reviews != null), force_push_blocked: ((.allow_force_pushes.enabled // false) == false), deletions_blocked: ((.allow_deletions.enabled // false) == false)}'
    All three fields should be true.
  5. Report result
    Protected {owner}/{repo}@{branch}: PRs required, force pushes blocked, deletions blocked.

Remove Protection Workflow

Use this only when the user explicitly asks to remove protection.

  1. Detect default branch (same as step 2 above)
  2. Remove branch protection
    gh api -X DELETE \
      -H "Accept: application/vnd.github+json" \
      "repos/{owner}/{repo}/branches/{branch}/protection" \
      --silent
  3. Report result
    Removed branch protection from {owner}/{repo}@{branch}.

Error Handling

  • gh not installed -> Error: GitHub CLI not found. Install: https://cli.github.com/
  • Not authenticated -> Error: Not authenticated with GitHub. Run: gh auth login
  • No GitHub remote -> Error: No GitHub remote found. Is this a GitHub repository?
  • 403/404 from API -> Error: Admin permissions required to set branch protection
  • Protection already exists -> safe to re-apply (PUT is idempotent)
  • Protection does not exist on remove -> safe (DELETE returns 204 or 404)

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.