git post-receive hook not running

user943301 picture user943301 · Nov 21, 2011 · Viewed 26.9k times · Source

I have a bare repo server-side, and I am able to successfully commit and push from my local machine. However, the post-receive hook is not running. Details:

  • Using SSH as protocol
  • I have renamed the standard "post-receive.sample" to "post-receive"
  • This file has -rwxr-xr-x permissions
  • The file is owned by the same user that owns the repo, which is the same SSH user that logs in and pushes
  • The actual pushing goes fine; files are updated - it's just the hook that does not run
  • I tried putting echo "Some text" before and after the hook, but this is not shown (see: Post Commit Hook Not Running).
  • Hook script is included below, although this appears not to be causing the problem
  • Using git 1.7.0.4 on Ubuntu 10.04

.

user@server:/home/repos/project1/hooks# cat post-receive
#!/bin/sh
echo "Hook is running..."
export GIT_WORK_TREE=/home/web/project1/www/
git checkout -f
rm -rf /home/web/project1/www/temp/

Answer

Nick F picture Nick F · Mar 20, 2013

In order for a Git hook to run, it needs to have permissions set to allow it to be executable. If a hook doesn't seem to be running, check the permissions, and make sure it's executable. If it isn't you can make all hooks executable like this:

chmod ug+x .git/hooks/*

...or if you want to make a single hook (eg. post-receive) executable:

chmod ug+x .git/hooks/post-receive

(Thanks to this post)