Skip to content

Instantly share code, notes, and snippets.

@junoteam
Forked from zamicol/post-receive
Last active April 23, 2016 19:47
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 junoteam/4ff081c25da21ee192f6 to your computer and use it in GitHub Desktop.
Save junoteam/4ff081c25da21ee192f6 to your computer and use it in GitHub Desktop.
#!/bin/sh
#Put this script into <gitProject>/hooks/post-receive on the production server
#Make sure this script has execute permissions (chmod +x post-receive)
#You can create a group (like "git"), make it owner of this file, and add
#every user that needs to push to the that group.
echo 'start repo to prod'
PROJPATH="PushDirectoryLocationHere"
GITPATH="LocationOfYourGitDirectoryHere"
OWNER="OwnerOfTheProject example: www:www"
function push(){
git --work-tree=$PROJPATH --git-dir=$GITPATH checkout -f master
find $PROJPATH/* -type d -exec chmod 775 {} \;
find $PROJPATH/* -type f -exec chmod 664 {} \;
chown -R $OWNER $PROJPATH/*
echo 'push complete'
}
#If executed from shell, push latest master commit regardless.
#This allows you to re-push by entering "./post-receive" from the command line.
if [ -t 0 ]; then
push
else
#Determine the branch, only push to prod on master.
while read oldrev newrev refname
do
branch=$(git rev-parse --symbolic --abbrev-ref $refname)
if [ "master" == "$branch" ]; then
echo 'Master branch. Pushing to prod'
push
else
echo 'Not on master. Not pushing to prod'
fi
done
fi
echo 'End repo to prod'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment