brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: core.hooksPath lets you keep git hooks in the repository

Git
~/tips/tip-git-hookspath-shared-hooks

git config core.hooksPath .githooks

Points git at a hooks folder you commit, so the whole team can share the same hooks.

Hooks in .git/hooks aren’t part of the repository, so they never reach anyone else. Pointing git at a normal folder fixes that.

mkdir .githooks
git config core.hooksPath .githooks

Put executable scripts in .githooks with the usual names, like pre-commit or commit-msg, and commit the folder. From then on, git runs hooks from there instead of from .git/hooks. A small example that blocks leftover conflict markers:

#!/bin/sh
git diff --cached --check || exit 1

Save it as .githooks/pre-commit, run chmod +x on it, and any commit with whitespace errors or conflict markers is stopped with a message.

The path is relative to the top of the working tree, so it works from any subfolder. You can also set it globally to one folder of personal hooks for all repositories.

The catch is that the setting itself isn’t shared. Every person who clones the repository still has to run git config core.hooksPath .githooks once, which I’d put in the readme or in a setup script. Git does this on purpose: a repository can’t make your machine run its scripts without you agreeing to it. And setting core.hooksPath means git ignores .git/hooks completely, so move any hooks you already had there.

Further reading: githooks documentation, git-config documentation: core.hooksPath

More Git tips git show-branch main feature git log --stat -5 git merge --no-ff feature -m "Merge feature" git merge --squash feature git merge --abort All Git tips (144) All topics

Link