0Pricing
Git Advanced: Monorepo, Submodules & Workflows · درس

مشاركة الخطافات مع الفريق باستخدام Husky

توجد خطافات Git المحلية خارج نظام التحكم في الإصدارات. تعلّم كيف توزّع Husky والأدوات المشابهة الخطافات على جميع المساهمين، بحيث تُطبّق بوابات الجودة باستمرار.

مشاركة الخطافات مع الفريق باستخدام Husky درس مجاني في Git Advanced: Monorepo, Submodules & Workflows على CoddyKit. هذا هو الدرس 4 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Git Advanced: Monorepo, Submodules & Workflows، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Git Advanced: Monorepo, Submodules & Workflows 4 دروس في المجموع.

بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.

The Distribution Problem

Git hooks live in .git/hooks, which is not part of the repository. So a pre-commit hook you write only runs on your machine.

To enforce standards across a team, hooks must be shareable and version-controlled.

The core.hooksPath Setting

Git can read hooks from a custom directory you commit to the repo via core.hooksPath. This is the foundation most tools build on.

git config core.hooksPath .githooks

Enter Husky

Husky is a popular tool for JavaScript projects that manages hooks via committed files and wires up core.hooksPath automatically on install.

npm install --save-dev husky

Initializing Husky

Run the init command. It creates a .husky/ directory and a sample hook, and sets up the prepare script.

npx husky init

The prepare Script

Husky relies on npm's prepare lifecycle so hooks are enabled automatically whenever a teammate runs npm install.

{
  "scripts": {
    "prepare": "husky"
  }
}

Writing a Pre-Commit Hook

Add commands to .husky/pre-commit. Since the file is committed, every contributor gets the same checks.

npm test
npm run lint

Running Only on Staged Files

Linting the whole project on every commit is slow. lint-staged runs tools only on the files you actually staged.

npx lint-staged

Configuring lint-staged

Map file patterns to commands. Below runs the formatter and linter only on staged JS files.

{
  "lint-staged": {
    "*.js": ["prettier --write", "eslint --fix"]
  }
}

Enforcing Commit Messages

A commit-msg hook can validate message format. Paired with commitlint, it enforces conventional commits across the team.

npx --no -- commitlint --edit $1

Tools for Other Ecosystems

Husky is Node-centric. Language-agnostic options include pre-commit (Python), lefthook (Go, very fast), and overcommit (Ruby). All solve the same distribution problem.

Hooks Are Not a Security Boundary

Remember: client hooks can be bypassed with --no-verify. They catch honest mistakes, but real enforcement must also live in CI and server-side hooks.

git commit --no-verify

Quick Check

Test your shared-hooks knowledge.

Recap

You can now share hooks across a team:

  • core.hooksPath points Git at a committed hooks directory
  • Husky automates setup via the prepare script
  • lint-staged runs checks only on staged files
  • commitlint enforces message format
  • Hooks complement, never replace, server-side and CI enforcement

This builds directly on your client-side and server-side hook lessons.

الأسئلة الشائعة

هل درس «مشاركة الخطافات مع الفريق باستخدام Husky» مجاني؟

نعم — نص درس «مشاركة الخطافات مع الفريق باستخدام Husky» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Git Advanced: Monorepo, Submodules & Workflows، انتقل إلى CoddyKit PRO. تتضمن دورة Git Advanced: Monorepo, Submodules & Workflows 4 دروس في المجموع.

ماذا ستتعلم في «مشاركة الخطافات مع الفريق باستخدام Husky»؟

توجد خطافات Git المحلية خارج نظام التحكم في الإصدارات. تعلّم كيف توزّع Husky والأدوات المشابهة الخطافات على جميع المساهمين، بحيث تُطبّق بوابات الجودة باستمرار. تتمرن على Git Advanced: Monorepo, Submodules & Workflows مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.

هل أحتاج إلى خبرة سابقة لأبدأ Git Advanced: Monorepo, Submodules & Workflows؟

لا تُشترط خبرة سابقة. Git Advanced: Monorepo, Submodules & Workflows على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 4 من أصل 4.

كم من الوقت يستغرق درس «مشاركة الخطافات مع الفريق باستخدام Husky»؟

معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.

هل يمكنني كتابة وتشغيل أكواد في درس Git Advanced: Monorepo, Submodules & Workflows هذا؟

نعم. كل درس في Git Advanced: Monorepo, Submodules & Workflows يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.

جميع الدروس في هذه الدورة

  1. خطافات Git من جانب العميل
  2. خطافات Git من جانب الخادم
  3. ضبط Git والاختصارات
  4. مشاركة الخطافات مع الفريق باستخدام Husky
← العودة إلى Git Advanced: Monorepo, Submodules & Workflows