Created
May 18, 2012 19:11
-
-
Save geekforbrains/2727108 to your computer and use it in GitHub Desktop.
Git post-receive rsync to remote server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
REPO=NAME_HERE | |
# Dir paths on remote server | |
# These are associated with branches within a git project | |
LIVE_BRANCH="master" | |
LIVE="git@host:/var/www/live/" | |
STAGE_BRANCH="develop" | |
STAGE="git@host:/var/www/stage/" | |
if ! [ -t 0 ]; then | |
read -a ref | |
fi | |
# Get branch name from ref head | |
IFS='/' read -ra REF <<< "${ref[2]}" | |
branch="${REF[2]}" | |
# Make tmp dir for extracting files and cleaning up .git (we dont want them on the live site) | |
tmpdir="/tmp/$REPO/$branch" | |
mkdir -p $tmpdir | |
# Assuming git is installed at /home/git/... | |
git --work-tree=$tmpdir --git-dir="/home/git/repositories/$REPO.git" checkout -f $branch | |
# If pushing to LIVE_BRANCH, deploy on LIVE | |
if [ "$LIVE_BRANCH" == "$branch" ]; then | |
rsync -vzre ssh --delete "$tmpdir/" $LIVE | |
fi | |
# If pushing to STAGE_BRANCH, deploy on STAGE | |
#if [ "$STAGE_BRANCH" == "$branch" ]; then | |
#rsync -vzre ssh --delete "$tmpdir/" $STAGE | |
#fi | |
rm -rf "/tmp/$REPO" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@jayralencar Yes, you can, as long as your shared host has Git installed (and you can SSH into your account, of course). I've even seen a page where the user compiled and installed Git in their home directory, but your hosting provider might not like it.