
- Authors

- Name
- Nadim Tuhin
- @nadimtuhin
I changed a hook in a worktree, committed, and the old hook ran anyway. Same behavior, as if I'd never touched it.
Here's why. Git keeps hooks in the common git directory, and every worktree shares it. The tracked copy in your branch (for example .githooks/pre-push) is just a file in the working tree. It does nothing until something installs it into .git/hooks.
You can ask git where it looks, right from inside the worktree:
git rev-parse --git-path hooks
# /path/to/main-checkout/.git/hooks
To prove it, I put a hook in the main checkout's .git/hooks/pre-commit that prints a line, then committed inside a separate worktree. The line printed.
The fix
An edit to the tracked hook doesn't apply until the installed copy is updated. You've got two options:
- Re-run whatever installs the hooks after you change them.
- Set
core.hooksPathto the tracked folder, so git reads the files you edit.
Next time a hook seems to ignore your change, check the installed copy before the tracked one.
Related posts
- TIL: piping into tail hides a failed command
A failed git push piped into tail still exited 0, and the script moved on. set -o pipefail makes the pipeline report the failure.
- TIL: 'No module named' after an update meant a stale process
My agent said httpx was missing. It was installed. The running process had started before the update and was still on the old environment.
- TIL: a gitignored sitemap goes stale (93 vs 123 URLs)
My IndexNow script read public/sitemap.xml and sent 93 URLs. The live sitemap had 123. The local copy is gitignored, so it only updates when I build.