Skillpedia
النشر والسحابة (DevOps)310k · #120

git-guardrails-claude-code

ما الذي تفعله

يضيف فحص أمان إلى Claude Code يوقف تنفيذ أوامر git معينة. وهي موجهة لمن يريدون منع الضرر العرضي بمستودع الشيفرة.

متى تستخدمها

  • ✓عندما تريد منع الوكيل من دفع الشيفرة عن طريق الخطأ.
  • ✓عندما تريد حجب الأوامر المدمّرة مثل git reset --hard.
  • ✓عندما تريد تطبيق قواعد الأمان هذه على مشروع واحد أو على كل مشاريعك.

رابط المهارة

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

انسخه والصقه في الذكاء الاصطناعي الذي تستخدمه (Claude أو ChatGPT أو Cursor) واطلب منه اتباع التعليمات.

طريقة الاستخدام

أسهل طريقة: انسخ الرسالة والصقها في الذكاء الاصطناعي الذي تستخدمه. سيقرأ المهارة وينفّذ تعليماتها.

رسالة جاهزة للصق

استخدم هذه المهارة لمساعدتي: https://github.com/mattpocock/skills/blob/main/skills/misc/git-guardrails-claude-code/SKILL.md اقرأ ملف SKILL.md في هذا الرابط ونفّذ تعليماته لمهمتي.
تريد أن يجد الذكاء الاصطناعي مهارات مثل هذه بنفسه؟ثبّت خادم Skillpedia MCP المجاني: سطر واحد، ويبحث في 15,000+ مهارة قبل كل مهمة.ثبّته في دقيقة واحدة →

مثال على ما تطلبه من الذكاء الاصطناعي

“اضبط خطافات الأمان حتى لا يتمكن Claude Code من الدفع إلى مستودع git الخاص بي أو إعادة ضبطه عن طريق الخطأ.”

5 مهارات جديدة كل أسبوع. قراءة في دقيقة واحدة.

كيف تعمل

ينسخ الوكيل سكربت الخطاف إلى مشروعك أو إلى مجلد الإعدادات في منزلك، ويربطه في ملف الإعدادات. وعندما تُحاول أمرًا محجوبًا، يوقفه الخطاف ويبلغ الوكيل بأنه لا يملك الصلاحية لتنفيذه.

المحتوى التقني (ملف 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 المحجوبة؟

عمليات الدفع بجميع أشكالها، و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
آخر تحديث
1‏/11‏/2026

هل هذه المهارة مفيدة؟

0

سجّل الدخول للتصويت.

التعليقات

  • …

المزيد من المهارات من هذا المستودع

مهارات مشابهة