Git post-receive hook to save branches into different folders
What if we want to work on a project, show demo to client from a specific folder and at the same time, be able to push other branches to the same repository and serve them to hidden folders?
#!/bin/sh
#
# modified by zigotica from
# http://www.ekynoxe.com/git-post-receive-for-multiple-remote-branches-and-work-trees/
# way more flexible now!
while read oldrev newrev ref
do
branch=`echo $ref | cut -d/ -f3`
if [ "master" = "$branch" ]; then
folder="current"
else
folder="${branch}"
fi
ROUTE="/usr/share/nginx/somewhere"
REPO="reponame"
FINAL="${ROUTE}/${REPO}/${folder}"
git --work-tree=${FINAL} checkout -f $branch
done
You will need to give your git user permissions to write to those folders, for instance:
chown git.git branchpath
Enjoy!
Written by Sergi Meseguer
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Branches
Authors
filipekiss
5.415K
zigotica
2.974K
Related Tags
#branches
#hook
#git hook
#repository
#git
#gitlab
#git branch
#post-receive
#git post-receive
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#