git-guardrails-claude-code
Skill2 starsChanged 2 months agoMITView on GitHub
Set up Claude Code hooks to block dangerous git commands (force-push, direct push to protected branches, reset --hard, clean, branch -D, etc.) before they execute. Use when user wants to prevent destructive git operations, add git safety hooks, or block git push/reset in Claude Code.
- Deletes or force-pushes
- Commits and pushes
121 other projects use a version of this, 120 of them edited.
Adopted by
Most recently taken up by
- 5thlayer/skillworksedited, first seen Nov 8, 2026
- dfirmin/compassedited, first seen Nov 8, 2026
- op3616windows/skillsedited, first seen Nov 8, 2026
- kazemcodes/skill-treeedited, first seen Nov 8, 2026
- itsryanarmani/skillsedited, first seen Nov 8, 2026
- shkodnik1917/claude-brainlabedited, first seen Nov 8, 2026
Used with
Projects with it also use setup-ts-deep-modules, writing-beats and 9 more.
Other files people use alongside this one.
Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
liufeng1976Skillsetup-ts-deep-modules
Wire dependency-cruiser into a TypeScript repo so each package is a deep module — implementation hidden in subfolders, reachable only through its entry-point files. User-invoked.
Also in 40 projects that use this
LesaniSkillwriting-beats
Shape an article as a journey of beats, choose-your-own-adventure style. The user picks a starting beat from the raw material, you write only that beat, then offer options for where to pivot next, beat by beat, until the article reaches a natural end. Use when the user has raw material and wants to assemble it as a narrative rather than an argument.
Also in 55 projects that use this
RoentekSkillloop-me
Grill me about specs for the workflows I want to build, within this workspace.
Also in 51 projects that use this
LesaniSkillwriting-fragments
Grilling session that mines the user for fragments — heterogeneous nuggets of writing (claims, vignettes, sharp sentences, half-thoughts) — and appends them to a single document as raw material for a future article. Use when the user wants to develop ideas before imposing structure, or mentions "fragments", "ideate", or "raw material" for writing.
Also in 55 projects that use this
ryotaroh180105Skillclaude-handoff
Hand the current conversation off to a fresh background agent that picks up the work immediately.
Also in 39 projects that use this
kennethkeimSkillubiquitous-language
Extract a DDD-style ubiquitous language glossary from the current conversation, flagging ambiguities and proposing canonical terms. Saves to UBIQUITOUS_LANGUAGE.md. Use when user wants to define domain terms, build a glossary, harden terminology, create a ubiquitous language, or mentions "domain model" or "DDD".
Also in 32 projects that use this
- +1 more from Lesani
Other versions121 projects use a version of this.
Word for word · 0
None found.
Edited · 120
- mattpocock/skills★ 309k64% same
- vinvcn/mattpocock-skills-zh-CN★ 5.5k23% same
- devcxl/mattpocock-skills-zh★ 52224% same
- amazingloft999-droid/mattpocock-skills★ 42264% same
- InditexTech/weavejs★ 26664% same
- loulanyue/skills★ 23164% same
- tt-a1i/matt-skills-with-to-goal★ 19264% same
- aurorasoft2/Matt_Pocock_Skills★ 13364% same
- Tresnanda/kybern★ 8364% same
- VisualxIntelligence/mattpocok-skills★ 5564% same
110 more not listed
Wrote their own version · 1
- chrislacey89/skills★ 4same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository31 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- ai-agent-pr-metadataSkill
- changesets-releaseSkill
- clarify-workSkill
- decompose-to-issuesSkill
- define-doneSkill
- design-composition-checkSkill
- diagnoseSkill
- docker-db-guardrailsSkill
- docker-volume-guardrailsSkill
- external-campaign-triageSkill
- external-pr-styleSkill
- external-pr-viabilitySkill
- git-identity-guardSkill
- hitl-blockerSkill
- open-code-review-setupSkill
- release-gateSkill
- resolving-merge-conflictsSkill
- review-gateSkill
- subagent-pipelineSkill
- tmux-orphaned-socketSkill
- to-prdSkill
- vps-cleanupSkill
- wizardSkill
- workflow-routerSkill
- write-prompt-guideSkill
- writing-for-agentsSkill
- cavemanSkill
- handoverSkill
- roastSkill
The file
We split this skill into the rules it gives an agent
4 rules. 1 is common, 0 are distinctive, and 3 are very specific to this project.
1
Common
Most of the 109 edited versions we read keep these.
0
Distinctive
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Common: line 23
When blocked, Claude sees a message telling it that it does not have authority to run the command.
- Very specific: line 29
Ask the user: install for this project only (.claude/settings.json) or all projects (~/.claude/settings.json)?
- Very specific: line 44
Add to the appropriate settings file, merging into any existing hooks.PreToolUse array — don't overwrite other settings:
- Very specific: line 68
Ask if the user wants to add or remove any protected branch names or command rules.
“Common” is measured: kept by at least 6 in 10 of the 109 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Setup Git Guardrails
Sets up a PreToolUse hook that intercepts and blocks a fixed list of destructive git commands before Claude executes them.
Source: adapted from mattpocock/skills — misc/git-guardrails-claude-code, imported 2026-08-26. Upstream blocks every invocation of git push, including plain feature-branch pushes. This adaptation narrows that to force-push and direct pushes to protected branches only, because system-level/core.md's git workflow requires routine feature-branch pushes for the standard worktree → branch → push → PR flow — blocking all pushes would make this repo's own workflow unusable. The rest of upstream's blocked-command list (reset --hard, clean -f/-fd, branch -D, bare checkout/restore) is unchanged.
What Gets Blocked
git pushwith--force/--force-with-lease/-fgit pushdirectly tomain,master, orstaginggit reset --hardgit clean -f/git clean -fdgit branch -Dgit checkout ./git restore .(bare, discards uncommitted changes)
Routine git push origin <feature-branch> is not blocked.
When blocked, Claude sees a message telling it that it does not have authority to run the command.
Steps
1. Ask scope
Ask the user: install for this project only (.claude/settings.json) or all projects (~/.claude/settings.json)?
2. Copy the hook script
The bundled script is at: scripts/block-dangerous-git.sh
Copy it to the target location based on scope:
- Project:
.claude/hooks/block-dangerous-git.sh - Global:
~/.claude/hooks/block-dangerous-git.sh
Make it executable with chmod +x.
3. Add hook to settings
Add to the appropriate settings file, merging into any existing hooks.PreToolUse array — don't overwrite other settings:
{
"hooks": {
"PreToolUse": [
{
"matcher": "Bash",
"hooks": [
{
"type": "command",
"command": "~/.claude/hooks/block-dangerous-git.sh"
}
]
}
]
}
}(Project scope: use "\"$CLAUDE_PROJECT_DIR\"/.claude/hooks/block-dangerous-git.sh" instead.)
4. Ask about customization
Ask if the user wants to add or remove any protected branch names or command rules. Edit the copied script's PROTECTED_BRANCHES array for branch names and is_dangerous_git_command for command rules.
5. Verify
The hook tokenizes each shell command segment, recognizes git and absolute paths to the Git executable, consumes Git global options, and then checks the subcommand arguments. This avoids matching quoted prose that merely mentions Git operations. Test both directions before trusting the hook in a new environment:
# Should exit 2 (BLOCKED) — real dangerous commands, one per pipe-test:
echo '{"tool_input":{"command":"git push origin main"}}' | <path-to-script>
echo '{"tool_input":{"command":"git -C /tmp/example reset --hard origin/main"}}' | <path-to-script>
# Should exit 0 (allowed) — routine push and prose that merely mentions these words:
echo '{"tool_input":{"command":"git push origin feature/my-branch"}}' | <path-to-script>
echo '{"tool_input":{"command":"gh issue create --body \"discusses git push and main\""}}' | <path-to-script>Then prove it fires live in-session: run a real (but harmless-context) git push --force or similar in the Bash tool and confirm the hook intercepts it with a PreToolUse:Bash hook error, per this repo's own update-config-style hook-construction discipline (pipe-test → jq -e schema check → live fire proof).
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.

