🔀Git Hook
Also known as Git Hooks, Pre-Commit Hook, pre-commit, commit-msg Hook
A script Git runs on its own, like a check just before each commit.
Think of it like
Think of it like a guard at a door. Before you go through, the guard checks your ticket.
Example
Why it matters
It catches mistakes on your own machine, before anyone else sees them.
Definition
Example code
bash
#!/bin/sh
# .git/hooks/pre-commit
npm test || exit 1Common mistake
Key takeaways
- 1Runs on its own. Git calls it at a set moment.
- 2Can say no. An error stops the commit.
- 3Local only. Each copy has its own hooks.