Deploy a project using Git push

后端 未结 19 956
囚心锁ツ
囚心锁ツ 2020-11-22 07:06

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

19条回答
  •  花落未央
    2020-11-22 08:03

    For Deployment Scenario

    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):

    1. Copy over your .git directory to your web server
    2. On your local copy git remote add live ssh://user@host:port/folder
    3. On remote: git config receive.denyCurrentBranch ignore
    4. On remote: nano .git/hooks/post-receive and add this content:

      #!/bin/sh GIT_WORK_TREE=/var/www/vhosts/example.org git checkout -f

    5. On remote: chmod +x .git/hooks/post-receive

    6. Now you can push there with git push live

    Notes

    • This solution works with older git versions (tested with 1.7 and 1.9)
    • You need to make sure pushing to github/bitbucket first, so you'll have a consistent repo on live
    • If your .git folder is within document root make sure you hide it from the outside by adding to .htaccess (source):

      RedirectMatch 404 /\..*$

提交回复
热议问题