如何阻止推送到远程的主分支 [英] How to block push to master branch on remote

查看:99
本文介绍了如何阻止推送到远程的主分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么办法可以直接阻止代码直接向主人推送?我尝试在 .git / hooks / update 中添加一个脚本:
$ b

Is there any way to block code push directly to master? I tried adding a script in .git/hooks/update:

#!/bin/sh
if [ $USER != "git-repo-admin" ];
then
  if [ "$1" == refs/heads/master ];
  then
    echo "Manual pushing to this repo is restricted"
    exit 1
  fi
fi

但这不起作用 - 大家仍然可以推。我想只允许特定的用户推送到主人并阻止他人。

But this doesn't work - Everybody can still push. I want to allow only specific users to push to master and block others.

推荐答案

原始脚本非常完美,我只需要在远程服务器上将它从 .git / hooks / update.sample 更改为 .git / hooks / update

The original script was perfect, I just needed to rename it from .git/hooks/update.sample to .git/hooks/update on the remote server and make sure it's executable.

#!/bin/sh
if [ $USER != "git-repo-admin" ];
then
  if [ "$1" == refs/heads/master ];
  then
    echo "Manual pushing to this repo is restricted"
    exit 1
  fi
fi

这篇关于如何阻止推送到远程的主分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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