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
In this repository22 other files it gives its agents.
- AGENTS.mdAGENTS.md
- changelog-bump-verSkill
- gh-copilot-review-readSkill
- gh-copilot-review-resolveSkill
- gh-copilot-reviewSkill
- gh-cr-submitSkill
- gh-issue-fixSkill
- gh-issueSkill
- gh-pr-mergeSkill
- gh-pr-reviewSkill
- gh-prSkill
- gh-releaseSkill
- git-branchSkill
- git-commitSkill
- git-pushSkill
- make-changelogSkill
- mir-skills-installSkill
- mir-skills-updateSkill
- python-venvSkill
- save-planSkill
- session-noteSkill
- work-reportSkill
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
- Distinctive: line 15
Verify the protection was applied correctly
- Distinctive: line 20
Use this skill when the user wants to protect the default branch from direct pushes so that changes can only be merged through pull …
- Distinctive: line 25
Must be inside a git repo with a GitHub remote
- Very specific: line 27
If gh not installed -> error: Error: GitHub CLI not found.
- Very specific: line 28
If not authenticated -> error: Error: Not authenticated with GitHub.
- Very specific: line 29
If not admin -> error: Error: Admin permissions required to set branch protection
- Very specific: line 70
All three fields should be true.
- Distinctive: line 79
Use this only when the user explicitly asks to remove protection.
- Very specific: line 100
No GitHub remote -> Error: No GitHub remote found.
≈ “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.
Files
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
ghnot 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
- Validate GitHub access
gh auth status - Detect default branch and repo
Parse the output to getgh repo view --json nameWithOwner,defaultBranchRef --jq '"\(.nameWithOwner) \(.defaultBranchRef.name)"'OWNER/REPOandBRANCH. - Apply minimal branch protection
Replacegh 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{owner}/{repo}and{branch}with the values from step 2. - Verify protection
All three fields should begh 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)}'true. - 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.
- Detect default branch (same as step 2 above)
- Remove branch protection
gh api -X DELETE \ -H "Accept: application/vnd.github+json" \ "repos/{owner}/{repo}/branches/{branch}/protection" \ --silent - Report result
Removed branch protection from {owner}/{repo}@{branch}.
Error Handling
ghnot 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)
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
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.

