Skip to content

How to Fix Git Hook Not Executing Error

DodaTech Updated 2026-06-24 2 min read

In this tutorial, you'll learn about How to Fix Git Hook Not Executing Error. We cover key concepts, practical examples, and best practices.

You installed a Git hook but it does not run — the hook script lacks execute permission, has the wrong filename, or Git is configured to use a different hooks directory.

The Problem

You created .git/hooks/pre-commit but committing still works without the hook running:

git commit -m "test"

No hook output is shown.

Step-by-Step Fix

Step 1: Check the hook filename

Hooks must have the exact filename:

Hook Filename
Pre-commit pre-commit
Pre-push pre-push
Post-commit post-commit
Post-merge post-merge
Pre-receive pre-receive
Post-receive post-receive
# WRONG — wrong filename
.git/hooks/pre-commit.sh

# RIGHT
.git/hooks/pre-commit

Step 2: Make the hook executable

# WRONG — not executable
-rw-r--r-- 1 user user 1024 .git/hooks/pre-commit

# RIGHT — add execute permission
chmod +x .git/hooks/pre-commit

Verify:

ls -la .git/hooks/pre-commit
-rwxr-xr-x 1 user user 1024 .git/hooks/pre-commit

Step 3: Add the correct shebang

#!/bin/sh

Or:

#!/usr/bin/env bash

Step 4: Add a test line to verify execution

#!/bin/sh
echo "Hook is running!"
exit 0

Step 5: Check core.hooksPath

git config core.hooksPath

If set, Git uses that directory instead of .git/hooks/.

# If hooksPath points elsewhere, either move hooks or unset it
git config --unset core.hooksPath

Step 6: Use shared hooks directory

For team-shared hooks:

git config core.hooksPath .githooks
chmod +x .githooks/pre-commit

Commit the hooks directory to the repository.

Prevention Tips

  • Always run chmod +x after creating hooks
  • Use .githooks directory for team-shared hooks
  • Name hooks exactly as required (no extensions)
  • Test hooks with exit 1 to verify they block
  • Use git hook run <hook-name> to test hooks (Git 2.36+)

Common Mistakes with hook not running

  1. Placing the wildcard pattern first in case expressions, making all subsequent patterns unreachable
  2. Using head and tail instead of pattern matching, causing runtime errors on empty lists
  3. Forgetting that lazy evaluation defers computation until the value is forced, causing space leaks with unevaluated thunks

These mistakes appear frequently in real-world GIT code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

### Why does my pre-commit hook run but not block the commit?

The hook must exit with a non-zero status to block: exit 1. If the hook exits with exit 0, Git assumes it passed. Check the last line of your hook script for the exit code.

How do I bypass hooks temporarily?

Use git commit --no-verify to skip pre-commit and commit-msg hooks. Use git push --no-verify to skip pre-push hooks. Use this sparingly — hooks enforce quality standards.

Where can I find example Git hooks?

Example hooks are in .git/hooks/ with .sample extension. Run ls .git/hooks/*.sample to see them. Remove the .sample extension and make them executable to enable them. For example, mv .git/hooks/pre-commit.sample .git/hooks/pre-commit.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro