git-guard
Skill0 starsChanged 8 months agoMITView on GitHub
Set up Claude Code hooks to block dangerous git commands before they execute, including `git push`, `git reset --hard`, `git clean`, `git branch -D`, and checkout or restore of the working tree. Use this skill when the user wants to prevent destructive git operations, protect a repo from accidental pushes or resets, add git safety hooks, or make git commands safer.
- Deletes or force-pushes
- Commits and pushes
In this repository2 other files it gives its agents.
- devil-advocateSkill
- skill-scanner-scansSkill
The file
We split this skill into the rules it gives an agent
6 rules. About 0 are common, 4 are distinctive, and 2 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.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 18
When blocked, Claude sees a message explaining that it does not have authority to run the command.
- Very specific: line 24
Ask whether to install for this project only in .claude/settings.json or for all projects in ~/.claude/settings.json.
- Distinctive: line 41
Add this to the appropriate settings file.
- Very specific: line 83
If the settings file already exists, merge the hook into the existing hooks.PreToolUse array instead of overwriting other settings.
- Distinctive: line 87
Ask whether to add or remove any blocked patterns, then edit the copied script accordingly.
- Distinctive: line 91
Run a quick test:
≈ “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
Git Guard
Set up a PreToolUse hook that intercepts and blocks dangerous git commands before Claude executes them.
What Gets Blocked
git push, including force variantsgit reset --hardgit clean -fandgit clean -fdgit branch -Dgit checkout .andgit restore .
When blocked, Claude sees a message explaining that it does not have authority to run the command.
Steps
1. Ask scope
Ask whether to install for this project only in .claude/settings.json or for all projects in ~/.claude/settings.json.
2. Copy the hook script
The bundled script is at scripts/git-guard.sh.
Prerequisite: jq must be installed.
Copy it to the target location based on scope:
- Project:
.claude/hooks/git-guard.sh - Global:
~/.claude/hooks/git-guard.sh
Make it executable with chmod +x.
3. Add the hook to settings
Add this to the appropriate settings file.
Project scope:
{
"hooks": {
"PreToolUse": [
{
"matcher": "Bash",
"hooks": [
{
"type": "command",
"command": "\"$CLAUDE_PROJECT_DIR\"/.claude/hooks/git-guard.sh"
}
]
}
]
}
}Global scope:
{
"hooks": {
"PreToolUse": [
{
"matcher": "Bash",
"hooks": [
{
"type": "command",
"command": "~/.claude/hooks/git-guard.sh"
}
]
}
]
}
}If the settings file already exists, merge the hook into the existing hooks.PreToolUse array instead of overwriting other settings.
4. Ask about customization
Ask whether to add or remove any blocked patterns, then edit the copied script accordingly.
5. Verify
Run a quick test:
echo '{"tool_input":{"command":"git push origin main"}}' | <path-to-script>The script should exit with code 2 and print a BLOCKED message to stderr.
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.

