Skip to content

Instantly share code, notes, and snippets.

@AlexandrKolesnikov
Created September 11, 2018 20:33
Show Gist options
  • Select an option

  • Save AlexandrKolesnikov/18c93bf198c46584400ada6b0cc6c3a5 to your computer and use it in GitHub Desktop.

Select an option

Save AlexandrKolesnikov/18c93bf198c46584400ada6b0cc6c3a5 to your computer and use it in GitHub Desktop.
Git Basic "post-receive" auto-deploy hook
#!/bin/bash
set -eu
TARGET="/home/YOUR_PROJECT/deploy-folder"
GIT_DIR="/home/YOUR_PROJECT/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="$TARGET" --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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment