Skip to content

Instantly share code, notes, and snippets.

@Glutexo
Last active August 29, 2015 14:05
Show Gist options
  • Save Glutexo/c94779896d0e8f22fd5f to your computer and use it in GitHub Desktop.
Save Glutexo/c94779896d0e8f22fd5f to your computer and use it in GitHub Desktop.
Simple script to use git instead of SCP for app deployment.
#!/bin/sh
# Checkouts the repository into the webserver application folder.
# Inspired by http://www.sitepoint.com/one-click-app-deployment-server-side-git-hooks/ by Matthew Setter.
# The script assumes that the bare repository directory name (somename.git) is same as the deployment
# directory name, just without the .git extension (somename). The destination path (htdocs) needs to be
# changed according to your environment (line 14, DEPLOYPATH variable).
read OLDREV NEWREV REFNAME
CURRENTDIR=`pwd | grep -o [^/]\\\\+$`
DEPLOYDIR=`echo "$CURRENTDIR" | sed s/\\\\.git$//`
LOGFILE="./post-receive.log"
DEPLOYPATH="/home/glutexo/public_html/$DEPLOYDIR"
echo "\`git push\` $(date +%F\ %T)" >> "$LOGFILE"
echo "$REFNAME: $OLDREV → $NEWREV" >> "$LOGFILE"
echo "\`GIT_WORK_TREE=\"$DEPLOYPATH\" git checkout -f\`" >> "$LOGFILE"
GIT_WORK_TREE="$DEPLOYPATH" git checkout -f
echo "✓\n" >> "$LOGFILE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment