
Git Guardrails
FreePrevent destructive git operations in Claude Code.
Free · Opens the source repo
What Git Guardrails does
Git Guardrails is a skill designed to enhance safety when using git commands within Claude Code by intercepting and blocking potentially dangerous operations. This skill is particularly useful for developers who want to prevent accidental data loss or repository corruption due to commands like git push, git reset --hard, and others that can lead to irreversible changes. By setting up this skill, users can ensure that critical git commands are safeguarded against unintended execution.
The skill works by implementing a PreToolUse hook that checks for specific git commands before they are executed. If a user attempts to run any of the blocked commands, such as git push --force or git branch -D, Claude Code will display a message indicating that the command is not authorized. This proactive approach helps maintain the integrity of the project and provides a safety net for developers who may be working under tight deadlines or in complex environments.
Setting up Git Guardrails is straightforward. Users can choose to apply the hooks to a specific project or globally across all projects. The bundled script, block-dangerous-git.sh, needs to be copied to the appropriate hooks directory and made executable. Additionally, users can customize the list of blocked commands to fit their specific needs, making this skill flexible and adaptable to various workflows.
Overall, Git Guardrails is an essential tool for developers who prioritize safety in their version control practices. By preventing the execution of harmful git commands, this skill helps maintain a stable and reliable development environment, allowing developers to focus on writing code without the fear of making irreversible mistakes.
When to use it
Use Git Guardrails when you want to add safety measures to git operations in Claude Code, especially in collaborative or critical projects.
When not to use it
This skill may not be suitable for advanced users who require full control over git commands without restrictions.
What you can build with it
Prevent Accidental Pushes
Use Git Guardrails to block accidental pushes to remote repositories, safeguarding against unintentional data loss.
Team Collaboration
In a team setting, implement Git Guardrails to ensure all members adhere to safe git practices and avoid destructive commands.
Project-Specific Safety
Apply Git Guardrails to specific projects where data integrity is critical, ensuring that only safe commands are executed.
How to install Git Guardrails
View source1. Install with the skills CLI
npx skills add mattpocock/skills/git-guardrails-claude-code --agent claude-code2. Or install it manually
Download the skill folder and drop it into ~/.claude/skills/ for all projects, or .claude/skills/ to scope it to one repo. Restart Claude Code so it picks up the new skill.
Anthropic's agentic coding CLI, and the reference implementation of Agent Skills. Drop a skill folder into ~/.claude/skills and Claude Code loads it automatically whenever a task matches the skill's description. Claude Code docs
Inside SKILL.md
Written by mattpocockSetup Git Guardrails
Sets up a PreToolUse hook that intercepts and blocks dangerous git commands before Claude executes them.
What Gets Blocked
git push(all variants including--force)git reset --hardgit clean -f/git clean -fdgit branch -Dgit checkout ./git restore .
When blocked, Claude sees a message telling it that it does not have authority to access these commands.
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:
Project (.claude/settings.json):
{
"hooks": {
"PreToolUse": [
{
"matcher": "Bash",
"hooks": [
{
"type": "command",
"command": "\"$CLAUDE_PROJECT_DIR\"/.claude/hooks/block-dangerous-git.sh"
}
]
}
]
}
}
Global (~/.claude/settings.json):
{
"hooks": {
"PreToolUse": [
{
"matcher": "Bash",
"hooks": [
{
"type": "command",
"command": "~/.claude/hooks/block-dangerous-git.sh"
}
]
}
]
}
}
If the settings file already exists, merge the hook into existing hooks.PreToolUse array — don't overwrite other settings.
4. Ask about customization
Ask if user wants to add or remove any patterns from the blocked list. Edit the copied script accordingly.
5. Verify
Run a quick test:
echo '{"tool_input":{"command":"git push origin main"}}' | <path-to-script>
Should exit with code 2 and print a BLOCKED message to stderr.
Frequently asked questions about Git Guardrails
Similar skills
Release Candidate Preparation
Streamline your OpenAI Agents release process.
Gitmoji
Generate expressive commit messages with emojis.
GitHub Release
Automate your GitHub library release process effortlessly.
Commit Message Storyteller
Generate meaningful commit messages from your git diffs.
Author Contributions
Trace author contributions across branches in Git.
Implementation Kickoff
Streamline your code implementation process with ease.
