Git post-receive hook not running following push

2020-03-05 03:13发布

I have a website hosted on an Amazon EC2 instance (running Ubuntu 12.04). I want to be able to be able to push changes to the server using git and then use a post-receive hook to checkout in the working directory. So on the server in the hooks directory I have a file named post-receive containing:

#!/bin/sh
GIT_WORK_TREE=/home/ubuntu/beta git checkout -f

The file has the permissions: -rwxrwxr-x (i.e. it is executable).

On my local machine, when I push to the git repo on the server, the push is successful and the git repo is updated. The post-receive hook is not run, however. If I run the hook manually, it runs fine and updates the working directory.

The git push is carried out over SSH and uses the same user as if I were running the hook manually.

Any ideas why the hook will not run automatically?

Thanks.

1条回答
我想做一个坏孩纸
2楼-- · 2020-03-05 03:38

I've set up an local identical test (ie I cloned from a local folder) and it works fine.

To see if the script is executed at all I've added a simple touch to see if it modifies any files

My post-receive looks like this

#!/bin/sh

touch /Users/raven/git_tests/live/.git/hooks/i_ve_been_run
GIT_WORK_TREE=/Users/raven/git_tests/live git checkout -f

Make sure that your hook is named exactly post-receive or it won't work.

查看更多
登录 后发表回答