1

I´m using git for a django webproject. I have a bare git repo on my server and push my commits from my local machine into it. I also have a testserver on my local machine but I would like to have 2 versions of the website on the server. one version as live site (master branch) and one version as testserver (develop branch). So I need 2 working directories.

I would like to use the post-receive hook to

  1. update my master branch working directory (for the live site on server)
  2. update my develop branch working directory (for my test site on server)

normally I would do

$ cat > hooks/post-receive
#!/bin/sh
GIT_WORK_TREE=/path/www.example.org git checkout -f
$ chmod +x hooks/post-receive

but GIT_WORK_TREE seems not to be the right choice here I guess? Is there a better way?

how can I define the working directories for branches?

2 Answers 2

2

according to article at digitalocean instead of GIT_WORK_TREE you need a combo of --work-tree and --git-dir options:

git --work-tree=/var/www/html --git-dir=/home/demo/proj checkout -f

and for post-receive script it ends up being slightly different construct than what you have:

#!/bin/bash
while read oldrev newrev ref
do
    if [[ $ref =~ .*/master$ ]];
    then
        git --work-tree=/var/www/html --git-dir=/home/demo/proj checkout -f
    fi
done
1
  • this is exactly what I need
    – Dude
    Apr 6, 2015 at 14:35
2

Suggestion:

#!/bin/sh

echo
echo "*** Moving to Live ***"
echo

cd /path/to/project || exit
unset GIT_DIR
git pull origin master

echo
echo "*** Pulling to Live ***"
echo                                               

/etc/init.d/nginx restart
#exec git-update-server-info

Took from my server and works well for me.

Don't forget to fix the path, the remote and the restart command.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .