Post Commit Hook Not Running Post Commit Hook Not Running git git

Post Commit Hook Not Running


I'll leave this here as an answer because I stumbled upon my own answer for when my post-commit hook wasn't running:

chmod +x .git/hooks/post-commit

Probably applies to any kind of hook. In fact, probably applies to any kind of script.


Try putting some echo lines before and after the perl line like this:

echo "post-commit started"perl ...........echo "post-commit finished"

This way you can confirm if the script is actually running, because when you run

git commit

you should see

post-commit startedpost-commit finished

Towards the end of your output.


My post-commit script wasn't being called because:

I had named the script post-commit.sh, rather than just post-commit.

To enable a hook script, put a file in the hooks subdirectory of your .git directory that is named appropriately (without any extension) and is executable. From that point forward, it should be called. We’ll cover most of the major hook filenames here. See git-scm

Not sure why I had in my head that hooks needed the bash file extension.

I also didn't realize hook scripts cannot have file extensions. For example,

If you want to use the bundled hook scripts, you’ll have to rename them; their file names all end with .sample

Hope this helps someone.