Originally published at omerbinsaleem.com by Omer Bin Saleem (Omer Saleem).
In a linked worktree, husky's runner folder was missing, so commits ran no hooks at all. Copying it in exposed a second trap, and a local clone fixed both.
How to do it
- Check first whether hooks run at all. Husky's runner folder
.husky/_is generated and gitignored, andcore.hooksPath=.husky/_resolves per worktree. A linked worktree has no such folder, so commits there ran no pre-commit, commit-msg or pre-push hook. - Copying
.husky/_in makes the hooks run, but a hook that falls back to Docker can still fail. Our gitleaks step mounted only the worktree, whose.gitfile points at<main>/.git/worktrees/<name>, outside the mount, so it stopped with "not a git repository". - Commit from a local clone instead:
git clone -q --no-checkout <main repo> <dir>. A local clone hardlinks the objects, so the container can read them. Do not use--shared, because its alternates point at host paths. - In the clone, run
checkout --detach <origin/branch SHA>andremote set-url origin <remote URL>, copy user.name and user.email,cp -R .husky/_, setcore.hooksPath .husky/_, and symlinknode_modules. Commit and push from there, and delete the clone oncegit ls-remoteshows the SHA. - Read the working tree after each commit. The clone's local main was 114 commits behind, so lint-staged's
nx format:writereformatted 30 app files that were never staged. The commit held only the staged files;git show --name-only HEAD,git statusandgit restore --worktree -- .cleared the rest. - Keep the guard rails while you fix it: never
--no-verify, and do not quietly install a local gitleaks, since every future commit would move off the pinned Docker version.
Prompt to copy
I commit from a linked git worktree in a repo that uses husky. Check whether hooks really run here: read `git config core.hooksPath`, check that folder exists in this worktree, and list the hooks that would fire. Never use --no-verify or install a tool. If the runner is missing or a Docker hook cannot see the repo, set up a local clone with `git clone --no-checkout` (never --shared) at my branch SHA, copy the hooks folder and git identity, symlink node_modules, and show each command before running it. After the commit, show `git status` so I can restore files a formatter touched outside the commit. I am Omer Bin Saleem, a frontend chapter lead who builds with AI every day. One practical AI hack a day at omerbinsaleem.com. LinkedIn: omer-bin-saleem · Instagram: @iomerbinsaleem.
Written with AI assistance, from my own work notes.