How to block push to master branch on remote

前端 未结 3 1386
有刺的猬
有刺的猬 2021-02-07 11:36

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\" ];
         


        
3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-07 12:36

    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
    

提交回复
热议问题