The following is mainly taken from this article from Digital Ocean, but includes other issues/fixes I ran into along the way.

Server setup

  • Log into server and create bare git repo for the site. I keep my html files at /var/www/ so I put the repo for that same site at /var/www/

    cd /var/www/

    mkdir repo.git && cd repo.git

    git init --bare

    Then create a file in repo.git/hooks called post-receive

    nano hooks/post-receive

    That file should look like this:

    while read oldrev newrev ref
        if [[ $ref =~ .*/master$ ]];
            echo "Master ref received.  Deploying master branch to production..."
            git --work-tree=/var/www/ --git-dir=/var/www/ checkout -f
            echo "Ref $ref successfully received.  Doing nothing: only the master branch may be deployed on this server."

    And then make it executable:

    chmod +x hooks/post-receive

Local Machine Setup

  • Now back on the local machine, go to the project's git repo, add a connection to the remote repo.

    git remote add live ssh://

    The remote name "live" can be anything.

    Then anytime you want to deploy, run:

    git push live master

    The post-receive script has a check to only allow the master branch to be deployed.

    **If there are issues, check the permissions!

Deploying a Jekyll site

If your site is compiled into a dist folder of some kind, as with jekyll, your post-receive script will need to be updated. Steps for jekyll:

  • Must have ruby, jekyll, and JS runtime (node.js) on the server.

    **May run into issues if using node version manager on the server. See this and/or this.

    Update the post-receive hook:

  • #!/bin/bash
    git clone $GIT_REPO $TMP_GIT_CLONE
    rm -Rf $TMP_GIT_CLONE
  • **GOTCHAS**The "jekyll" command in the post-receive script was not found when I ran git push, so I added a JEKYLL variable pointing to the output of 'which jekyll' (line 5) per this github issue/discussion.

    But still no "jekyll", so I changed /bin/ to /wrappers/ per this stack answer.

    And then success.

Other stuff: