Overview

Git hooks allow developers to automate tasks and enforce standards directly within the version control workflow. They are stored in the .git/hooks directory of a repository.

Common Hooks

  • pre-commit: Runs before a commit is created (e.g., to run linting or tests).
  • commit-msg: Runs after the commit message is written (e.g., to enforce Conventional Commits).
  • pre-push: Runs before code is pushed to a remote repository.
  • post-merge: Runs after a successful merge (e.g., to install new dependencies).

Benefits

  • Enforce Standards: Prevent bad code or poorly formatted messages from entering the repository.
  • Automation: Automate repetitive tasks like running tests or generating documentation.

Related Terms