Is it possible to deploy a website using git push
? I have a hunch it has something to do with using git hooks to perform a git reset --hard
on the
In our scenario we're storing the code on github/bitbucket and want to deploy to live servers. In this case the following combination works for us (that is a remix of the highly upvoted answers here):
.git
directory to your web servergit remote add live ssh://user@host:port/folder
git config receive.denyCurrentBranch ignore
On remote: nano .git/hooks/post-receive
and add this content:
#!/bin/sh
GIT_WORK_TREE=/var/www/vhosts/example.org git checkout -f
On remote: chmod +x .git/hooks/post-receive
git push live
If your .git
folder is within document root make sure you hide it from the outside by adding to .htaccess
(source):
RedirectMatch 404 /\..*$