Skip to content

Instantly share code, notes, and snippets.

@mdrmike
Forked from lemiorhan/post-receive
Last active September 15, 2020 15:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mdrmike/92b5ad3a2ece8d3b86f1acfc170431a4 to your computer and use it in GitHub Desktop.
Save mdrmike/92b5ad3a2ece8d3b86f1acfc170431a4 to your computer and use it in GitHub Desktop.
Post-receive hook to deploy the code being pushed to production branch to a specific folder
#!/bin/bash
target_branch="master"
working_tree="/var/www/html/stage.reddoorlivinglb.com/"
while read oldrev newrev refname
do
branch=$(git rev-parse --symbolic --abbrev-ref $refname)
if [ -n "$branch" ] && [ "$target_branch" == "$branch" ]; then
GIT_WORK_TREE=$working_tree git checkout $target_branch -f
NOW=$(date +"%Y%m%d-%H%M")
git tag release_$NOW $target_branch
echo " /==============================="
echo " | DEPLOYMENT COMPLETED"
echo " | Target branch: $target_branch"
echo " | Target folder: $working_tree"
echo " | Tag name : release_$NOW"
echo " \=============================="
cat << EOF > $working_tree'git_release.log'
/===============================
| DEPLOYMENT COMPLETED
| Date: $NOW
| Branch: $branch
| Target folder: $working_tree
\==============================
EOF
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment