0

I have two remote repositories being managed by my local git repository:

  • origin
  • stage

I have a post-receive hook for each remote:

#!/bin/sh
git --work-tree=/var/www/REMOTENAME --git-dir=/var/repo/REMOTENAME.git checkout -f 

However, when I push non-master branches, the work tree does not get updated. For example, if I have a branch called 'test', I would run:

git push stage test

and I would not see any changes on the remote's work tree.

If I run:

git checkout master
git merge test
git push stage master

I do see the changes on the remote's work tree.

My goal is to be able to use a workflow that allows me to separate development on multiple branches and push non-master branches to stage.

Any help would be greatly appreciated.

Raphael Rafatpanah
  • 19,082
  • 25
  • 92
  • 158

1 Answers1

2

You have to specify a branch to checkout in your post-receive hook. The default branch used is master. This is why the behavior is different when you push a non-master branch.

The branch can by known in a separated shell command. branch=$(git rev-parse --symbolic --abbrev-ref $1). (Source Git branch in a hook )

Then, add $branch at the end of your checkout command.

Community
  • 1
  • 1
Flows
  • 3,675
  • 3
  • 28
  • 52