🔀 Git: Fix a Hook Script Getting Skipped After a Repo Move
Git’s local hooks live under .git/hooks, or wherever core.hooksPath points, a location deliberately never cloned, copied, or carried along by a repository move, because hooks are local machine configuration rather than versioned repository content. Moving a repository’s working directory to a new path on disk, or recreating it via a fresh clone on a new machine, silently leaves every previously-configured hook behind, since there was never any linkage between the hook files and the repository’s tracked content for a move operation to preserve.
🔎 The Problem
# Original setup: hook manually placed, works fine cp pre-commit-lint.sh .git/hooks/pre-commit chmod +x .git/hooks/pre-commit # After `mv ~/old-path/repo ~/new-path/repo` (or a fresh clone # of the same remote on a teammate's machine): # .git/hooks/pre-commit never existed there to begin with - # commits silently skip the lint check with no warning at all
✅ Fix: Version the Hooks, Don’t Just Install Them Locally
- Store hook scripts as tracked files inside the repository, such as a /githooks directory, and set
core.hooksPathto point at it, so every clone of the repository gets the same hooks automatically instead of relying on a manual copy step per machine. - Add a setup script that every contributor runs once after cloning, which symlinks or copies the tracked hook files into .git/hooks, documenting the one manual step that
core.hooksPathwould otherwise eliminate. - Verify active hooks with
ls -la .git/hooksorgit config core.hooksPathright after any repository move or fresh clone, since a missing hook produces no error on the commits that skip it, only its absence, which is easy to miss.
🚨 Why This Is Dangerous
- A pre-commit hook enforcing lint rules or secret scanning that silently stops running after a repo move means every commit from that point on skips the exact safety check the team was relying on, with nothing in the commit history showing it was ever bypassed.
A hook isn’t part of your repository’s history — it’s part of whichever machine happened to have it installed, and a move takes you to a machine that never did.




