From git
This skill should be used when the user attempts git operations via bash, or when Claude detects bash being used for git commands. Automatically detects direct git command usage and suggests using git MCP instead, providing equivalent MCP tool calls.
How this skill is triggered — by the user, by Claude, or both
Slash command
/git:git-bash-preventionThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
Prevent direct bash git commands and guide users to use git MCP instead. This skill automatically detects when bash is used for git operations and provides equivalent MCP alternatives, ensuring consistent tool usage and policy compliance.
Prevent direct bash git commands and guide users to use git MCP instead. This skill automatically detects when bash is used for git operations and provides equivalent MCP alternatives, ensuring consistent tool usage and policy compliance.
git commit, git push, git pull, etc. via bashgit command in bash executionMonitor for git commands in bash execution:
# Detected patterns:
git commit
git push
git pull
git branch
git merge
git status
git log
git add
git checkout
git reset
git revert
git clean
git restore
[any other git command]
Detection triggers when:
git statuscat file | git applycd repo; git push$(git status) or `git log`(git commit) or { git status; }Determine if command is:
Allowed (query-only):
git statusgit loggit diffgit blamegit showgit branch -l (list only)Actionable (requires MCP):
git addgit commitgit pushgit pullgit mergegit rebasegit resetgit checkoutgit stashgit branch (create/delete)git taggit worktreeForbidden (always block):
git reset --hardgit clean -fgit revertgit restore (not --staged)When actionable git command detected:
Acknowledge the intent
Detected: git commit -m "Fix bug"
Explain why MCP is better
Git MCP provides:
- Policy enforcement (commit messages, confirmations)
- Automatic attribution (Co-Authored-By)
- Ticket tracking integration
- Safety checks and validations
Show MCP equivalent
Instead of:
$ git commit -m "Fix bug"
Use git MCP:
> Call Bash tool? No, use Git MCP tool instead
Execute via MCP (if appropriate)
Using git MCP commit tool with:
- Message: "Fix bug"
- Apply policies
- Enforce format rules
git config user.name "Name"
Action: Suggest configuring via project setup instead of bash
echo "message" | git commit -F -
Action: Use git MCP directly, avoid pipes
#!/bin/bash
git commit -m "Auto commit"
Action: Convert script to use git MCP or execute commands directly
git log --oneline | grep "feat:" | head -5
Action: Use git MCP query tools directly
For query-only commands (status, log, diff):
ℹ️ Using bash for git queries
You can use git MCP for better integration:
$ git-mcp status (Shows formatted output)
Action: Suggest but allow
For actionable commands (commit, push, branch):
⚠️ Bash git command detected: git commit
This bypasses:
- Commit confirmation checks
- Message format validation
- Automatic attribution
- Policy enforcement
Use git MCP instead for:
- Safety checks
- Policy compliance
- Automatic formatting
Action: Redirect to MCP, don't execute bash
For forbidden operations (reset --hard, clean -f, revert):
❌ Destructive git operation blocked: git reset --hard
This command is forbidden because:
- Irreversible data loss risk
- No recovery mechanism
- Destructive operations not supported
Use git MCP safely or alternative approach.
Action: Block execution entirely, no override available
Common git commands mapped to MCP equivalents:
| Bash Command | MCP Tool | Notes |
|---|---|---|
git status | query status | Query only |
git log | query log | Query only |
git diff | query diff | Query only |
git commit | execute commit | Applies policies |
git add | execute stage | Applies policy checks |
git push | execute push | Requires confirmation |
git pull | execute pull | Updates working tree |
git branch | execute branch | Create/delete |
git checkout | execute checkout | Switch branch |
git stash | execute stash | Temporary storage |
git tag | execute tag | Create/delete tags |
git reset --hard | BLOCKED | Destructive |
git clean -f | BLOCKED | Destructive |
This skill is typically triggered by PreToolUse hook:
Event: PreToolUse
Condition: tool === "Bash" AND command contains "git "
Action: Invoke git-bash-prevention skill
Hook can:
You're running: git log --oneline
This works fine in bash! If you want:
• Formatted output: Use git MCP
• Integration with workflow: Use git MCP
• Otherwise: This bash command is OK
You're running: git commit -m "Fix bug"
⚠️ This bypasses git policies!
Better approach:
1. Use git MCP commit tool
2. Policies enforced automatically
3. Message validated
4. Attribution added
Should I use git MCP instead? (Yes/No)
You're running: git reset --hard origin/main
❌ This is blocked!
Reason: Irreversible data loss risk - not supported
Your options:
1. Use git MCP safe alternatives
2. Use git revert (creates new commit)
3. Contact team lead for override
For detailed bash prevention rules:
references/git-bash-rules.md - Complete bash git detection patternsnpx claudepluginhub harry-jk/claude-plugin --plugin gitProvides complete Git expertise for all operations: repo management, branch strategies, conflict resolution, history rewriting/recovery, advanced commands like rebase/cherry-pick, and platform workflows for GitHub/Azure DevOps/Bitbucket. Safety guardrails for destructive actions.
Provides Claude Code bash patterns for PreToolUse hooks, command chaining, CLI orchestration, git workflows, custom commands, and handling bash permissions, failures, security guards.
Guides Git workflows in Claude Code: detects repo state, crafts conventional commits, creates PRs via GitHub CLI, manages branches, resolves merge conflicts.