git服务器端钩子-仅推送特定分支 [英] git server side hook - only specific branches will be pushed

查看:64
本文介绍了git服务器端钩子-仅推送特定分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是git hook的新手.我想确保仅将分支(以BT开头)推入/更新到存储库.因此,无法更新master/current分支.我怎样才能做到这一点?我想它应该是更新脚本的一部分,对吧?

i' m very newbie to git hooks. I' d like to make sure that to the repository only branches will be pushed / updated which starts with BT. So no update is possible to master / current branch. How can i achieve that? I guess it should be part of the update script, right?

推荐答案

它可能是 pre-receive 钩子.

#!/bin/bash

#sample
z40=0000000000000000000000000000000000000000
while read old new ref;do
    #fail if it's not a branch or the name of the branch does not start with BT
    if [ "${ref:0:13}" != "refs/heads/BT" ];then
        echo "Error: not allowed to update $ref"
        exit 1
    fi

    #deal with other cases if necessary
    #create a ref, branch or tag
    if [ "$old" = "$z40" ];then
        :
    fi

    #delete a ref, branch or tag
    if [ "$new" = "$z40" ];then
        :
    fi
done

这篇关于git服务器端钩子-仅推送特定分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆