🔀 The Hook Everyone Assumed Was Already Installed
A hooks/ folder committed to the repository (containing a pre-commit script the team relies on to catch lint errors, secrets, or formatting issues) does absolutely nothing on its own – git only ever executes scripts from .git/hooks, which is a local, per-clone directory that is never populated by cloning the repository, since .git/ itself isn’t tracked content. A brand new clone has an empty .git/hooks folder (aside from the .sample files git ships by default) regardless of how carefully the team’s actual hook script is maintained in the repo.
🔎 The Problem
# Repo layout, carefully maintained and reviewed like any other file: # hooks/pre-commit <- the team'"'"'s actual lint/secret-scan script # scripts/setup-hooks.sh <- copies hooks/* into .git/hooks (never run) git clone git@example.com:team/project.git cd project # .git/hooks/ contains only git'"'"'s own *.sample files right now. git add . git commit -m "quick fix" # Commits instantly - the team'"'"'s pre-commit script never ran, because # nothing installed it into .git/hooks for THIS clone. No error, no # warning: git simply has no hook registered at all for this event.
✅ Fix: Install Hooks Automatically, Don’t Rely on a Manual Step
- core.hooksPath (git config core.hooksPath hooks) points git directly at a tracked, versioned folder instead of .git/hooks – this is the most reliable fix, since it removes the copy-into-.git step entirely and makes the hook active the moment the config is set, with no separate install script to forget to run.
- Where core.hooksPath isn’t an option (an older git version, or a tool like Husky already managing hooks a specific way), a documented setup step run immediately after cloning – and ideally automated via a package manager’s postinstall script – closes the gap, as long as it’s something that actually runs rather than something a README merely asks a developer to remember.
- A CI pipeline step that independently re-runs the same lint/secret checks the pre-commit hook was meant to catch is the real safety net – a hook that silently isn’t installed on one developer’s machine is a productivity gap, but CI catching the same issue before merge is what actually prevents it from reaching the main branch.
⚠️ Why Nobody Notices Until Something Slips Through
- Everyone who set up their local environment before the hook was introduced, or through a process that happened to install it, has it working – so the bug is invisible to the very people most likely to be asked whether hooks are working, since their own setup is the one place it isn’t broken.
- This surfaces almost exclusively through a NEW team member’s first few commits, or a machine reimage/fresh clone by an existing member – exactly the situations where nobody is specifically checking whether hooks got installed, because installing them was never presented as a distinct, necessary step in the first place.
A pre-commit script sitting in the repository is documentation of intent, not an active hook – git only listens to what’s already inside .git/hooks, and cloning never puts it there for you.
