如何阻止推送到远程的主分支

问题描述:

有什么办法可以直接阻止代码直接向主人推送?我尝试在 .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