How to protect main/master branch of remote repo using git commands or any other Commands?

83 Views Asked by At

I am using Bonobo Git Server and i want to protect my main/master branch So, no one can push in master/main branch.

There is no such option in Bonobo Git Server to protect my branch.

This script of per-receive is not working

#!/bin/sh

while read oldrev newrev refname
do
    # Check if the branch being pushed is "main"
    if [[ $refname == refs/heads/main ]]; then
       # If not allowed to push to "main", reject the push
       echo "Error: Pushing to 'main' branch is not allowed." >&2
       exit 1
    fi
done
1

There are 1 best solutions below

0
Dmitry On

The hook must be on the server side, not where you clone it to.

Assuming your repositories are stored here on the server: go to ~\App_Data\Repositories\<RepositoryName>

add your hook under hooks directory.

You should already have some default hook samples there e.g. : pre-receive.sample

put your content into that file and remove .sample part of the file.

You should get your hook working.