msysgit error with hooks: "git error: cannot spawn .git/hooks/post-commit: No such file or directory"

Add the SHEBANG to the first line of hook, like so:

#!/bin/sh
echo "executing post-commit"
exit 0

This had me stumped for a while as well and I saw that adding the shebang fixed it. In SVN world, while in *nix we have a "pre-commit" script and in Windows we had "pre-commit.bat" and SVN automatically picked up the bat file in Windows. Git doesn't seem to pick up a pre-commit.bat ( or any hook ) and adding the shebang to the hook file worked.


I'm using SourceTree and git LFS and had a similar issue: cannot spawn .git/hooks/pre-push.

The fix was to delete the pre-push file (opening it revealed it was badly corrupted) and restart SourceTree at which point it regenerates the pre-push file and everything is back to normal.


If you have the SHEBANG and it still fails, make sure you have <path_to_git>\bin set in your path environment variable.

You'll probably also have <path_to_git>\cmd if you installed it to work from the command-line.