Luke Oliff.

TIL: Conditional Git Hooks With core.hooksPath

·TIL·1 min read·Luke Oliff

Git hooks are per repo scripts that run on commit, push, and other events. By default they live in .git/hooks which is not committed. core.hooksPath lets you put them somewhere better.

git config core.hooksPath .githooks

Now git runs hooks from the .githooks directory which you can commit to your repo.

.githooks/
  pre-commit
  pre-push
  commit-msg

Every clone gets the hooks automatically. No more asking teammates to run setup scripts or copy hook files around.

Do the hooks need to be executable?

Yes. Run chmod +x .githooks/* to make them executable before committing.

Does this work with shared configs?

Set core.hooksPath in the repo’s .gitconfig or use an init.templateDir for org wide defaults.