1

I have a remote bare git repository created following:

@server:~$ mkdir -p /home/myuser/domain.git && chmod 770 /home/myuser/domain.git && cd /home/myuser/domain.git && git init --bare

With a post-receive hook:

@server:~$ nano hooks/post-receive

The hook script is:

#!/bin/sh
git --work-tree=/var/www/domain --git-dir=/home/myuser/domain.git checkout -f

It has permission to execute:

@server:~$ chmod +x hooks/post-receive

However, it only changes the website when I push to the master branch.

Why? The remote HEAD is always master, even if I push to another branch.

Medical physicist
  • 2,510
  • 4
  • 34
  • 51

1 Answers1

0

By default, it checkout the master branch.

You would need to specify which branch to checkout, depending on the branch which has just been pushed and received.

Here is an example of a hook with a specific branch checkout:

#!/bin/bash

while read oldrev newrev ref
do
    branch=`echo $ref | cut -d/ -f3`
    GIT_WORK_TREE=/path/to/local/checkout git checkout -f $branch
done

Be sure to not push multiple branches at the same time, or only the last branch would be checked out.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250