kniessner
4/24/2018 - 8:25 PM

Git deploy to webspace

Git deploy to webspace

#!/bin/bash
        TRAGET="/www/repositories/"
        GIT_DIR="/www/repositories/project.git"
        BRANCH="master"

        while read oldrev newrev ref
        do
                # only checking out the master (or whatever branch you would like to deploy)
                if [[ $ref = refs/heads/$BRANCH ]];
                then
                        echo "Ref $ref received. Deploying ${BRANCH} branch to production..."
                        git --work-tree=$TRAGET --git-dir=$GIT_DIR checkout -f
                else
                        echo "Ref $ref received. Doing nothing: only the ${BRANCH} branch may be deployed on this server."
                fi
        done

on the server


git init --bare ./project.git nano project.git/hooks/post-receive chmod +x project.git/hooks/post-receive


on the client


git remote add live ssh://@/www/repositories/project.git git push live +master:refs/head/master