问题
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.
回答1:
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.
来源:https://stackoverflow.com/questions/30640210/git-post-receive-hook-for-push-to-deploy-only-works-with-master