brewly — Ch.10 · Let hooks check your commits
Exercise 3 of 6
Before you start
Hooks
A hook is a script git runs at certain moments. pre-commit runs before a commit is made and commit-msg checks its message. If a hook fails, there is no commit.
Hooks normally live in .git/hooks, which is not shared. Teams keep theirs in a committed folder, here .githooks, and everyone switches it on once with the setting core.hooksPath. Open the scripts to see what they check.
This practice terminal cannot run shell scripts in general. It understands the simple checks these two make.
- git config core.hooksPath <folder>
- use the hooks in that folder
- git add <file>
- stage a file
- git commit -m "feat: what you added"
- commit with a message
- git commit --no-verify -m "WIP: what it is"
- commit without running the hooks
When to skip a check
--no-verify is for the rare case where the check does not fit, such as saving half-done notes on your own branch. It is not a way to get past a check that found a real problem.
You can edit src/cart.js here: change the code, then press Save.
Graph
- e44154f chore: add commit hooksHEAD → mainorigin/main
- 1354d06 Add menu page
- 619eb3b Style the order button
- 5fc44ac Initial commit