Git-based website deployment workflow
I ended up making the public content owned by the git
user, and readable by all. Then, I did the following to set up the hooks:
Assuming the repository is called mysite
:
Create a detached work tree that will act as the webroot (as the user
git
)mkdir /var/www/mysitecd /path/to/repository/mysite.gitgit config core.worktree /var/www/mysitegit config core.bare falsegit config receive.denycurrentbranch ignore
Add a post-receive hook that will update the website and set correct permissions for it
touch hooks/post-receivechmod +x hooks/post-receivevim hooks/post-receive
The post-receive script:
#!/bin/shgit checkout -fchmod -R o+rX /var/www/mysite
Update: Here is a better solution.
Note: earlier versions of this howto depended on setting the git config variables core.worktree to the target directory, core.bare to false, and receive.denycurrentbranch to ignore. But these changes are not needed if you use GIT_WORK_TREE (which didn't work when I first wrote the howto), and the remote repository can remain bare.