Share git hooks

Step 1: Create a Tracked Hooks Folder

In the root of your project, create a new directory to hold your hooks (e.g., .githooks or git-hooks).

Step 2: Add Your Hook Scripts

Inside that new .githooks folder, create your hook files (like pre-commit, pre-push, etc.) without any file extension.

#!/bin/sh

echo "Running pre-commit checks..."
# Your linter or test commands here
npm run lint-check or pytest

Step 3: Make the Hooks Executable

chmod +x .githooks/pre-commit

Step 4: Configure Git to Use the New Path

Now, you need to tell Git to look inside .githooks instead of .git/hooks. Run this command:

git config core.hooksPath .githooks

How to automate this for your team

{
  "name": "your-project",
  "version": "1.0.0",
  "scripts": {
    "prepare": "git config core.hooksPath .githooks"
  }
}
init:
	pip install -r requirements.txt
	git config core.hooksPath .githooks
#!/bin/sh
# setup.sh

echo "Setting up local git hooks..."
git config core.hooksPath .githooks
echo "Done!"

Once this is configured, you can safely git add and git commit the entire .githooks folder, ensuring everyone on the team uses the exact same automation.