Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am attempting to setup GIT to deploy my project to different locations based on the branch. (I think this is what I want to do anyway).
My current setup is this: Local dev machine running Netbeans to make changes. Remote server hosting GIT projects (same server running apache) - 2 subsites exist a and a

What I would like to do is have 1 GIT project (MyProject) and create a new feature branch. Any commits done to the new feature branch would push to Once the features have been tested and then merged into the master branch, it would push to I have looked at GIT's post-receive hooks and was able to use "git checkout -f" command to pull on the site however that only pulls the master branch and not the new feature branch. I do not have any funding to use a third party to make this work, and would prefer to stay within GIT but have full root access to the web server if there is a package to install which would help control this. Any suggestions would be great!

EDIT Here is what my post-receive looks like currently:

umask 002
cd /srv/git/projects/APP.git
git push --mirror backupLocation:APP
branch=$(git branch | grep "*" | sed "s/* //")

if [ "$branch" == "master" ]
    GIT_WORK_TREE=/srv/www/ssl_apps/APP git checkout -f
    GIT_WORK_TREE=/srv/www/ssl_apps/APPtest git checkout -f
share|improve this question
What are you using to deploy? – nickgrim Feb 8 '13 at 12:02
I am still using Git's post-receive hooks for all deployments, please refer to my edit above for the code I am currently using. – Brian Feb 10 '13 at 4:22

our system in a nutshell:

if a branch was pushed, git post-receive hooks increments a number in static file /var/www/<branch>.version

at client server (there are multiple servers, multiple installations per server):

cron script runs every minute, it checks<branch>.version for every branch

if version was incremented it does the update:

cd /var/<branch>.subsite;
git pull --rebase

one minute delay (max) is OK for our purposes

share|improve this answer
Your post-receive hooks are vital here, yet not included in the answer. – gertvdijk Dec 14 '12 at 14:39

You can use reset --hard <branchname> to put your working copy in a detached-HEAD state; change the latter part of your post-receive hook to:

if [ "$branch" == "master" ]
    GIT_WORK_TREE=/srv/www/ssl_apps/APP git reset --hard $branch
    GIT_WORK_TREE=/srv/www/ssl_apps/APPtest git reset --hard $branch
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.