Raphael Rafatpanah
Raphael Rafatpanah

Reputation: 19967

How to trigger post-receive hook with non-master branch

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

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.

Upvotes: 0

Views: 296

Answers (1)

Flows
Flows

Reputation: 3863

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.

Upvotes: 2

Related Questions