Mitul Mitul - 16 days ago 5
Linux Question

Git --How to block push to master branch on remote

Is there any way to block code push directly to master ?

I tried by 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 its not working still all can push directly to master

I want to allow only specific user to push to master and block others

Please help

Answer
#!/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

This code is perfect only need to change the name from update.sample to update inside the .git/hooks/update folder on remote server!