Deploy a project using Git push

后端 未结 19 1168
囚心锁ツ
囚心锁ツ 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 07:58

    I am using the following solution by toroid.org, which has a simpler hook script.

    on the server:

    $ mkdir website.git && cd website.git
    $ git init --bare
    Initialized empty Git repository in /home/ams/website.git/
    

    and install the hook on the server:

    $ mkdir /var/www/www.example.org
    $ cat > hooks/post-receive
    #!/bin/sh
    GIT_WORK_TREE=/var/www/www.example.org git checkout -f
    GIT_WORK_TREE=/var/www/www git clean -f -d # clean directory from removed files
    
    $ chmod +x hooks/post-receive
    

    on your client:

    $ mkdir website && cd website
    $ git init
    Initialized empty Git repository in /home/ams/website/.git/
    $ echo 'Hello, world!' > index.html
    $ git add index.html
    $ git commit -q -m "The humble beginnings of my web site."
    
    $ git remote add web ssh://server.example.org/home/ams/website.git
    $ git push web +master:refs/heads/master
    

    then to publish, just type

    $ git push web
    

    There is a full description on the website: http://toroid.org/ams/git-website-howto

提交回复
热议问题