Many times I’ve been working in several projects when deployment of different webs according to a branch are necessary. Finally I just wrote a tiny Git hook script that helps me out with this matter, I hope it could help you as it does to me.
By example, for branch master I need that every time someone pushes commits to it, changes deploys in /path/to/my/deployment/unstable, and if branch stable is pushed, then changes are deployed in /path/to/my/deployment/stable.
The script I wrote uses the post-update hook, and cut to “parse” the revision name and provide the branch name, then I can use that name to set the path of the repo. After that I check if that directory exists, and then change the GIT_DIR to that path. Finally I change the position to that path and execute a simple git pull specifying the name of the branch.
Feel yourself free to use it.
#!/bin/bash # # An example hook script to prepare a packed repository for use over # dumb transports. # # To enable this hook, rename this file to "post-update". BRANCH=`echo $1 | cut -d '/' -f 3` if [ $BRANCH == 'master' ]; then STAGE='unstable' else STAGE=$BRANCH fi STAGE_PATH=/my/stage/path/$STAGE/ if [ -d $STAGE_PATH ]; then GIT_DIR=$STAGE_PATH/.git cd $STAGE_PATH git pull origin $BRANCH else echo 'Stage path for '$STAGE' not found' fi exec git update-server-info