Skip to content

Instantly share code, notes, and snippets.

@NicmeisteR
Last active May 15, 2020 18:18
Show Gist options
  • Save NicmeisteR/d023c66f2f6c39cab61812b8734a722e to your computer and use it in GitHub Desktop.
Save NicmeisteR/d023c66f2f6c39cab61812b8734a722e to your computer and use it in GitHub Desktop.
Git Hooks File
#!/bin/bash
# Location of our bare repository.
GIT_DIR="/var/www/halosouthafrica.co.za/repo"
# Where we want to copy our code.
TARGET="/var/www/halosouthafrica.co.za/temp"
while read oldrev newrev ref
do
# Neat trick to get the branch name of the reference just pushed:
BRANCH=$(git rev-parse --symbolic --abbrev-ref $ref)
if [[ $BRANCH == "refactoring" ]];
then
# Send a nice message to the machine pushing to this remote repository.
echo "Push received! Deploying branch: ${BRANCH}..."
rm -R /var/www/halosouthafrica.co.za/html/*
# "Deploy" the branch we just pushed to a specific directory.
git --work-tree=$TARGET --git-dir=$GIT_DIR checkout -f $BRANCH
cp -R /var/www/halosouthafrica.co.za/temp/dist/HaloSA/* /var/www/halosouthafrica.co.za/html
else
echo "Not master branch. Skipping."
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment