glossaryShell scripts placed in a repository's .git/hooks directory that Git executes automatically at specific points in the version control workflow.
Git provides over twenty hook points across the commit, merge, rebase, push, and receive workflows. Each hook is a script file named after the hook event (pre-commit, commit-msg, post-commit, pre-push, etc.) placed in .git/hooks and made executable. When Git reaches the corresponding lifecycle point, it runs the script; a non-zero exit code aborts the operation. Client-side hooks (pre-commit, commit-msg, post-commit, pre-push) run on the developer's machine and are not version-controlled in .git/hooks — each contributor must install them locally. This is why hook managers like Husky, lefthook, and pre-commit exist: they store hook definitions in the repository root and install them into .git/hooks on npm install or a setup command. Server-side hooks (pre-receive, update, post-receive) run on the Git server and enforce policy for pushes. They cannot be bypassed by individual developers. For commit message validation on the server side, tools like Gitea, GitHub, and GitLab also support status checks and branch protection rules that complement local hooks.
# pre-commit: run tests on staged files# commit-msg: validate message format against regex# post-commit: send webhook notification on commit# pre-push: run full test suite before push# prepare-commit-msg: pre-populate message templategit-agent init installs a commit-msg hook that validates the generated message against your project's conventional commit format. The hook integrates with git-agent's retry loop so rejected messages are automatically corrected without developer intervention.
brew install gitagenthq/tap/git-agentWhy are Git hooks not committed to the repository by default?Can git-agent work without its installed hook?What language must Git hooks be written in?