본문으로 건너뛰기
Skillpedia
배포 및 클라우드 (DevOps)310k · #120

git-guardrails-claude-code

하는 일

Claude Code에 특정 git 명령의 실행을 막는 안전 검사를 추가합니다. 코드 저장소가 실수로 손상되는 것을 막고 싶은 사람을 위한 스킬입니다.

사용하는 경우

  • ✓에이전트가 실수로 코드를 push하지 않도록 막고 싶을 때.
  • ✓git reset --hard 같은 파괴적인 명령을 차단하고 싶을 때.
  • ✓이 안전 규칙을 한 프로젝트에 적용할지 모든 프로젝트에 적용할지 정하고 싶을 때.

스킬 링크

https://github.com/mattpocock/skills/blob/main/skills/misc/git-guardrails-claude-code/SKILL.md

복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.

사용 방법

가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.

바로 붙여넣을 수 있는 메시지

Use this skill to help me: https://github.com/mattpocock/skills/blob/main/skills/misc/git-guardrails-claude-code/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
AI가 이런 스킬을 알아서 찾아 쓰길 원하시나요?무료 Skillpedia MCP를 설치하세요. 한 줄이면 작업마다 스킬 15,000+개 중에서 검색합니다.1분 만에 설치 →

AI에게 요청하는 예시

“Claude Code가 실수로 제 git 저장소에 push하거나 reset하지 못하도록 안전 훅을 설정해 주세요.”

매주 새 스킬 5개. 읽는 데 1분.

작동 방식

에이전트는 훅 스크립트를 프로젝트나 홈 설정에 복사하고 설정 파일에 연결합니다. 차단된 명령이 시도되면 훅이 그것을 막고, 에이전트에게 그 명령을 실행할 권한이 없다고 알립니다.

기술 내용 (원본 SKILL.md)

작성자의 영어 원문을 GitHub에서 그대로 가져왔습니다.

Setup 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 --hard
  • git clean -f / git clean -fd
  • git branch -D
  • git 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 the 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.

자주 묻는 질문

어떤 git 명령이 차단되나요?

모든 형태의 push, git reset --hard, git clean -f, git branch -D, 그리고 모든 파일에 대한 checkout이나 restore가 차단됩니다.

규칙이 적용되는 범위를 고를 수 있나요?

예. 스킬은 이 프로젝트에만 설치할지 모든 프로젝트에 설치할지 묻습니다.

명령이 차단되면 무슨 일이 일어나나요?

Claude는 그 명령에 접근할 권한이 없다는 메시지를 봅니다.

상세 정보

작성자의 원본 설명

Set up Claude Code hooks to block dangerous git commands (push, 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.

repo: mattpocock/skills

인기도

GitHub 스타
310k
순위
#120
라이선스
MIT
업데이트
2026. 11. 1.

이 스킬이 유용한가요?

0

로그인 투표하려면 로그인하세요.

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬