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!
The shell expands ~/
only when it is at the beginning of a word. You have it in the middle of a word.
You should write
#!/bin/sh
git --work-tree="$HOME/public_html" --git-dir="$HOME/repo/website" checkout -f master
On top of that, since ~
appears inside double-quotes, the character counts as "quoted" and would be left unmodified regardless of whether the shell could guess that --git-dir=
has some special meaning.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.