0Pricing
Git Advanced: Monorepo, Submodules & Workflows · Lektion

Hooks mit dem Team mithilfe von Husky teilen

Lokale Git-Hooks stehen außerhalb der Versionskontrolle. Lernen Sie, wie Husky und ähnliche Tools Hooks an alle Mitwirkenden verteilen, damit Qualitätsprüfungen zuverlässig ausgeführt werden.

Hooks mit dem Team mithilfe von Husky teilen ist eine kostenlose Git Advanced: Monorepo, Submodules & Workflows-Lektion auf CoddyKit. Dies ist Lektion 4 von 4. Du kannst die komplette Lektion unten kostenlos lesen – dann übst du sie direkt im Browser mit einem integrierten Code-Editor und einem KI-Tutor rund um die Uhr. Sie ist Teil des Git Advanced: Monorepo, Submodules & Workflows-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der Git Advanced: Monorepo, Submodules & Workflows-Kurs umfasst insgesamt 4 Lektionen.

Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.

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.

Häufig gestellte Fragen

Ist die Lektion „Hooks mit dem Team mithilfe von Husky teilen“ kostenlos?

Ja — der vollständige Text von „Hooks mit dem Team mithilfe von Husky teilen“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des Git Advanced: Monorepo, Submodules & Workflows-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der Git Advanced: Monorepo, Submodules & Workflows-Kurs umfasst insgesamt 4 Lektionen.

Was lerne ich in „Hooks mit dem Team mithilfe von Husky teilen“?

Lokale Git-Hooks stehen außerhalb der Versionskontrolle. Lernen Sie, wie Husky und ähnliche Tools Hooks an alle Mitwirkenden verteilen, damit Qualitätsprüfungen zuverlässig ausgeführt werden. Du übst Git Advanced: Monorepo, Submodules & Workflows mit praktischem Code, den du direkt im Browser ausführst, und ein 24/7 KI-Tutor beantwortet deine Fragen während du die Lektion bearbeitest.

Brauche ich Erfahrung, um Git Advanced: Monorepo, Submodules & Workflows zu starten?

Keine Vorkenntnisse erforderlich. Git Advanced: Monorepo, Submodules & Workflows auf CoddyKit ist für Anfänger bis fortgeschrittene Lernende strukturiert, sodass du hier starten oder von Anfang an beginnen und in deinem eigenen Tempo voranschreiten kannst. Dies ist Lektion 4 von 4.

Wie lange dauert die Lektion „Hooks mit dem Team mithilfe von Husky teilen“?

Die meisten CoddyKit-Lektionen dauern etwa 5–10 Minuten. Jede ist kompakt und interaktiv, sodass du stetig Fortschritte machst und genau dort weitermachst, wo du aufgehört hast – im Web und in der App.

Kann ich in dieser Git Advanced: Monorepo, Submodules & Workflows-Lektion Code schreiben und ausführen?

Ja. Jede Git Advanced: Monorepo, Submodules & Workflows-Lektion enthält einen integrierten Code-Editor, sodass du echten Code direkt in deinem Browser schreibst und ausführst und sofort KI-Feedback erhältst — ohne lokale Einrichtung erforderlich.

Alle Lektionen in diesem Kurs

  1. Git-Hooks auf der Clientseite
  2. Git-Hooks auf der Serverseite
  3. Git-Konfiguration und Aliase
  4. Hooks mit dem Team mithilfe von Husky teilen
← Zurück zu Git Advanced: Monorepo, Submodules & Workflows