I'm aware that there are numerous questions about that topic already, but I never really got it working the way I want.
I'm trying to setup an easy deploy workflow for a small site. I'm using this Tutorial for reference: https://halfthetruth.de/2011/09/13/using-git-to-deploy-a-website/
I setup everything like explained in the tutorial but I'm running into this problem:
This is when I try to push from my local repository:
example.com|master ⇒ git push production +master:refs/heads/master
Counting objects: 12, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (9/9), done.
Writing objects: 100% (12/12), 967 bytes | 0 bytes/s, done.
Total 12 (delta 3), reused 0 (delta 0)
remote: ********************
remote: Post receive hook: Updating website
remote: ********************
remote: fatal: No remote repository specified. Please, specify either a URL or a
remote: remote name from which new revisions should be fetched.
remote: fatal: Unable to create '/home/user/git/example.com.git/index.lock': Permission denied
To ssh://[email protected]/~/git/example.com.git
* [new branch] master -> master
My post-receive hook looks like this:
#!/bin/sh
echo "********************"
echo "Post receive hook: Updating website"
echo "********************"
export GIT_WORK_TREE=/usr/share/nginx/www/example.com
cd $GIT_WORK_TREE
sudo -u www-data git --work-tree=/usr/share/nginx/www/example.com --git-dir=$HOME/git/example.com.git pull
sudo -u www-data git --work-tree=/usr/share/nginx/www/example.com --git-dir=$HOME/git/example.com.git checkout master -f
My bare repository on the remote server is located in /home/user/git/example.com.git and the document root for nginx where the site should be served from is located in /usr/share/nginx/www/example.com.
It looks like there's some problem with running the git pull command in a non-git directory but I don't know how to resolve this. Anyone who could point me in the right direction?
Thanks!
~/www/example.com.gitisn't actually a git repo. Can you look in there?sudo -u www-data ls -la ~/www/example.com.git. Maybe try using the full path without the~shortcut? (/usr/share/nginx/www/example.com.git)git statusshows me the usual "fatal: This operation must be run in a work tree" for a bare repository.~is only expanded to$HOMEby the shell if it's at the beginning of an argument, which it isn't in this case. Replace it with$HOME.