Git post-receive hook to save branches into different folders
Saving a repository content into a server public folder is quite easy with a post-receive hook, see this gist for an example.
But what if we want to show demos to clients and at the same time, be able to push other branches to the same repository and serve them to hidden folders? For instance, you want one public folder for master (even rename that to /current) and then one for each development branch.
I created this for my gitlab setup:
#!/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













