Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Protect Github branches from being deleted

Tags:

github

It looks like the Github UI changed for settings/branches for a repo. I can no longer figure out how to prevent a branch from being deleted.

enter image description here

Does anyone know how to prevent a branch from being deleted? Aka, protect the branch?

like image 232
Alexander Mills Avatar asked Sep 11 '18 23:09

Alexander Mills


People also ask

How do I protect important branches in Git?

You can protect important branches by setting branch protection rules, which define whether collaborators can delete or force push to the branch and set requirements for any pushes to the branch, such as passing status checks or a linear commit history.

How do I block a specific branch in GitHub?

On GitHub.com, navigate to the main page of the repository. Under your repository name, click Settings . In the left menu, click Branches . Next to "Branch protection rules", click Add rule. Under "Branch name pattern", type the branch name or pattern you want to protect.

Who can manage branch protection rules on GitHub?

People with admin permissions to a repository can manage branch protection rules. Protected branches are available in public repositories with GitHub Free and GitHub Free for organizations, and in public and private repositories with GitHub Pro, GitHub Team, GitHub Enterprise Cloud, and GitHub Enterprise Server.

Can I delete a protected branch in GitLab?

Note that, since Dec. 4th 2019, you can grant all users with push access the ability to delete a protected branch by enabling Allow deletions. This user is third on the weekly GitLab leaderboard.


Video Answer


1 Answers

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.

About how the rule pattern works, it uses fnmatch to match against any pattern provided to find out the branches to which the rule applies. For eg :

  • Rule pattern as * would apply to all the branches
  • Rule pattern as release* would apply to all the branches whose name starts with release

Currently I don't think you can set any single rule pattern on GitHub (I have tried) to match multiple branches like for eg master and develop, since ideally {master,develop} should match both the branches, but currently it doesn't, and according to the fnmatch documentation {a,b} matches pattern a and pattern b if File::FNM_EXTGLOB flag is enabled

Check out more details on the above on GitHub help and the fnmatch documentation

like image 68
Madhu Bhat Avatar answered Oct 06 '22 09:10

Madhu Bhat