Git hooks
Definition
Git hooks start programs at defined points in the workflow of Git actions.
Git hooks are programs that Git executes on certain events, such as before a commit or when receiving a push. They can trigger checks or additional steps. Local and server-side hooks operate at different points and have different scopes of influence.
Simply explained
Git can automatically start a script at specified checkpoints, for example, to perform a check before a commit.
Why it matters in practice
Hooks can support recurring development rules and provide feedback early in the workflow, provided their setup and limitations are understood.
Example from business
Possible example: A local pre-commit hook checks selected file formats and warns of a formatting error before the commit.
Limits and pitfalls
- Local hooks are not a reliable substitute for central checks and are not simply adopted like normal project files. Foreign hook scripts execute code.
Origin & history
Git provides extension points for local work and remote acceptance processes. For example, a server-side pre-receive hook can react before accepting incoming reference changes.
Use in mid-sized companies
- An organization documents the required hooks, makes their setup reproducible, and supplements critical rules with checks on the shared server.
Frequently asked questions
Are Git hooks the same as webhooks?
No. Git hooks are programs started by Git; webhooks usually transmit events as HTTP requests between services.
Sources
- githooks. · Git-Projekt (o. J.): githooks.
Editorially reviewed on: