Git Hooks
Run scripts on commit, push, and other events
Git hooks automate quality checks by running scripts at key points in the Git workflow.
Git hooks are scripts that run automatically when specific Git events occur. They live in .git/hooks/.
client-side
server-side
pre-commit
Before commit is created
Run linters, formatters
commit-msg
After message is entered
Validate commit message
pre-push
Before push to remote
Run tests
post-commit
After commit is created
Notifications
pre-receive
Before accepting a push
Enforce policies
post-receive
After push is accepted
Deploy, notify
Terminal
# List available hooks $ ls .git/hooks/ applypatch-msg.sample commit-msg.sample pre-commit.sample pre-push.sample pre-rebase.sample # Hooks are scripts (bash, python, etc.) # Remove .sample suffix to activate $ cp .git/hooks/pre-commit.sample .git/hooks/pre-commit