In an EC2 AWS instance, I have a remote bare git repository created following:
@server:~$ mkdir -p /home/myuser/domain.git && chmod 770 /home/myuser/domain.git && cd /home/myuser/domain.git && git init --bare
With a post-receive hook:
@server:~$ nano hooks/post-receive
The hook script is:
#!/bin/sh
sudo git --work-tree=/var/www/domain --git-dir=/home/myuser/domain.git checkout -f
It has permission to execute:
@server:~$ chmod +x hooks/post-receive
I work on a local repo following:
@local:~$
git init
git remote add server server:/home/myuser/domain.git
git checkout -b www-dev
git add .
git commit -am "Initial"
However, when I push changes:
@local:~$ git push server www-dev
The hook fails:
remote: fatal: You are on a branch yet to be born
To server:/home/myuser/domain.git
06709ae..d1d7ead www-dev -> www-dev
And the website is not updated. Why?
I suspect that the problem is caused by the fact that git checkout -f
is called by the root. But only the root can write in /var/www/domain.