Skip to content

Instantly share code, notes, and snippets.

@natanshalva
Last active June 21, 2016 14:38
Show Gist options
  • Save natanshalva/41fe0ec2627b0c3c9157 to your computer and use it in GitHub Desktop.
Save natanshalva/41fe0ec2627b0c3c9157 to your computer and use it in GitHub Desktop.
This script updates sources on a remote sever on git push
#!/bin/bash
#
# How to :
# create repo on your remote server.
# cd "path-to-new-repo" and then : git init --bare
# then cd "hook".
# vim post-receive - and past this script in ( change the path as you want )
# save the file and change permission : chmod 777 post-receive
#
production="production"
production_working_tree="PATH_TO_DEPLOY"
stage="stage"
stage_working_tree="PATH_TO_DEPLOY"
dev="dev"
dev_working_tree="PATH_TO_DEPLOY"
while read oldrev newrev refname
do
branch=$(git rev-parse --symbolic --abbrev-ref $refname)
if [ -n "$branch" ] && [ "$production" == "$branch" ]; then
GIT_WORK_TREE=$production_working_tree git checkout $production -f
NOW=$(date +"%Y%m%d-%H%M")
git tag release_$NOW $production
echo " /==============================="
echo " | DEPLOYMENT COMPLETED"
echo " | Target branch: $production"
echo " | Target folder: $production_working_tree"
echo " | Tag name : release_$NOW"
echo " | Say thanks to: Natan Shalva"
echo " \==============================="
fi
if [ -n "$branch" ] && [ "$stage" == "$branch" ]; then
GIT_WORK_TREE=$stage_working_tree git checkout $stage -f
NOW=$(date +"%Y%m%d-%H%M")
git tag release_$NOW $stage
echo " /==============================="
echo " | DEPLOYMENT COMPLETED"
echo " | Target branch: $stage"
echo " | Target folder: $stage_working_tree"
echo " | Tag name : release_$NOW"
echo " | Say thanks to: Natan Shalva"
echo " \==============================="
fi
if [ -n "$branch" ] && [ "$dev" == "$branch" ]; then
GIT_WORK_TREE=$dev_working_tree git checkout $dev -f
echo " /==============================="
echo " | DEPLOYMENT COMPLETED"
echo " | Target branch: $dev"
echo " | Say thanks to: Natan Shalva"
echo " \==============================="
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment