After the first release of our product, we will be switching to a different branches for the main development and feature development. Is there a way to create a branch in such a way, so that we can protect it from being removed (accidentally or on purpose) unless you're a specific user (based on role or username)?
I tried to create a sample git repository in our local gitlab machine, then protected one of the branches from the option on the website, but then I was able to remove it with git push origin :branch_name
. Thanks in advance!
Will the solution work on github.com?
By default if you create a Branch protection rule for any branch, it Disables force-pushes to all matching branches and prevents them from being deleted . So if you create a rule with the pattern master , it would prevent the master branch from deletion by default.
In your project, select the "Settings" tab on the far right of the menu. In the menu on the left hand side of the "Settings" page, select "Branches". Under the "Protected Branches" section, select any branch you wish from force push and deletion. Thanks!
Configuring protected branches Scroll to find the Protected branches section. From the Branch dropdown menu, select the branch you want to protect and click Protect. In the screenshot below, we chose the develop branch. Once done, the protected branch will appear in the "Protected branches" list.
There are many ways to tackle this:
You can use branch permissions on the server by adding a pre-receive hook that protects your repository and add something like this to your config file in your bare repository:
[hooks]
allowedtomerge = user1,user2,user3
protectedbranches = master
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With