git-guard
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.
Works with
---
name: git-guard
description: 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.
license: MIT
---
# 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 variants
- `git reset --hard`
- `git clean -f` and `git clean -fd`
- `git branch -D`
- `git checkout .` and `git 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](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:
```json
{
"hooks": {
"PreToolUse": [
{
"matcher": "Bash",
"hooks": [
{
"type": "command",
"command": "\"$CLAUDE_PROJECT_DIR\"/.claude/hooks/git-guard.sh"
}
]
}
]
}
}
```
Global scope:
```json
{
"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:
```bash
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.More Git Workflows skills
git-commit
github/awesome-copilot
Execute git commit with conventional commit message analysis, intelligent staging, and message generation. Use when user asks to commit changes, create a git commit, or mentions "/commit". Supports: (1) Auto-detecting type and scope from changes, (2) Generating conventional commit messages from diff, (3) Interactive commit with optional type/scope/description overrides, (4) Intelligent file staging for logical grouping
git-workflow-and-versioning
addyosmani/agent-skills
Structures git workflow practices. Use when making any code change. Use when committing, branching, resolving conflicts, or when you need to organize work across multiple parallel streams. Use when cutting a release, choosing a semantic version bump, tagging, or writing a changelog.
resolve-merge-conflicts
warpdotdev/common-skills
Resolve Git merge conflicts by extracting only unresolved paths, conflict hunks, and compact diffs instead of loading whole files into context. Use when a merge, rebase, cherry-pick, or stash pop stops on conflicts, when `git status` shows unmerged paths, or when files contain conflict markers.

