Git post-receive hook for push-to-deploy only works with master

懵懂的女人 提交于 2019-12-23 02:47:14

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!