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.
Does anyone know how to prevent a branch from being deleted? Aka, protect the branch?
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.
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.
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.
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.
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 :
*
would apply to all the branchesrelease*
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
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