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

I'm having trouble getting post-recieve and post-commit hooks to work correctly with msysgit (Windows 7 Pro/32 and Ultimate/64). For post-commit hook I get the above error if I commit from either git-bash or the console, but it works fine if I commit through git-gui. For a post-recieve hook, all three give the same error.

I'm thinking this is some sort of permission or path error, but don't really have any clue where to start here.


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.