glossary

Git Hooks

Shell 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 template

git-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-agent
Why are Git hooks not committed to the repository by default?
The .git directory is never tracked by Git. Hooks live inside .git/hooks and must be installed separately by each contributor. Hook managers solve this by keeping hook source in the repo root (e.g. .husky/) and symlinking on setup.
Can git-agent work without its installed hook?
Yes. The hook is optional. Without it, git-agent still generates and commits messages; it just won't validate format against your project's specific rules or retry on rejection.
What language must Git hooks be written in?
Any language whose interpreter is available on the system. The hook file just needs a valid shebang line (#!/bin/sh, #!/usr/bin/env python3, #!/usr/bin/env node) and execute permission.