I have a similar setup to the one I'm creating on a new server, so I know the 'principle works'. I have a Git post-receive which looks likes this:
#!/bin/sh
git --work-tree="~/public_html" --git-dir="~/repo/website" checkout master -f
I have checked ten times that these are existing and correct folders :-)
To set up the Git repo I ran the following commands:
cd ~/repo/website
git init --bare
# Added content to post-receive file
chmod +x hooks/post-receive
# Verified that these permissions are set on the file
I have added (pushed) some content to the repo for testing purpose. Now, when I try to execute the command for testing with this command:
cd ~/repo/website && bash hooks/post-receive
I get this error:
fatal: not a git repository: '~/repo/website'
I then tried to completely delete the repo and make it from scratch. But on the 4th attempt I'm starting to think it's not the way forward ;-)
I read on related Stackoverflow threads that maybe the HEAD file was corrupted. However, it looks fine - and has also been re-made four times together with the other from-scratch attempts.
It's for deployment reasons I need to set the work-tree, etc. It works fine with the same setup on other servers.
I hope someone has a good idea how to resolve this. Thanks!