Deleting protected branches is hard #21793
-
Not long ago I requested Branch Protection on multiple branches, and that works great (thanks github!). However, there is one fatal flaw with it: Removing stale protected branches is really hard. For example, say my branch protection pattern is release-?.?, once I’ve released release-4.0 I want to delete release-3.0, but in order to do so, I have to remove my branch protection, delete it, then quickly add the branch protection back. It would be great if I could delete a protected branch as an admin with some kind of confirmation. |
Beta Was this translation helpful? Give feedback.
Replies: 18 comments 1 reply
-
Why not leave the protected branch up on GitHub? It’s always nice to have some kind of back-up to see where things come from. |
Beta Was this translation helpful? Give feedback.
-
We have tags for backup. The branch is just added noise and can confuse engineers creating new PRs. |
Beta Was this translation helpful? Give feedback.
-
This is interesting and you’re being impacted as we are too (but for a different reason). Please see my recent post: https://github.community/t5/How-to-use-Git-and-GitHub/Code-Review-Problems/td-p/14439 |
Beta Was this translation helpful? Give feedback.
-
I agree, this is a problem for us too. A lot of our protected branches only need to exist for a time, and then we remove them. It’d be nice to at least have admin delete rights on the branches list |
Beta Was this translation helpful? Give feedback.
-
The issue affects us, as well. Admins should have the right to delete protected branches, maybe with extra confirmation checkbox, like “I want to use my admin priviledges…” |
Beta Was this translation helpful? Give feedback.
-
We have a similar problem, we were trying to follow a similar development pattern as described here on stackoverflow and introduced branch protection and hooks for the story branches however they can’t be removed once the story is complete and merged in master. |
Beta Was this translation helpful? Give feedback.
-
Agree. |
Beta Was this translation helpful? Give feedback.
-
I just temporarily amended the Branch protection rule so that it applies to 0 branches, removed the desired branches, then reverted the rule. |
Beta Was this translation helpful? Give feedback.
-
I’ve done this too. It works but it’s not ideal |
Beta Was this translation helpful? Give feedback.
-
Hello @clphillips and everyone else in this thread! I’m very sorry for the delay, but I wanted to let you know that I’ve compiled all of this great feedback into a feature request and have sent it off to the product team. I can’t say if or when this feature might be implemented, but when it is implemented, it will be announced in the GitHub Changelog. Thanks! |
Beta Was this translation helpful? Give feedback.
-
Hi, We also need to be able to delete protected branches without being a developer for “feature/*” branches for instance that once merged into master cannot be deleted easily. We have to ask to an admin (me) and this doesn’t scale way or we have to change the branch policy, delete the branch, then re-set the branch policy again… this is annoying right ? |
Beta Was this translation helpful? Give feedback.
-
Enabling deleting branches for administrators, overruling it with a checkbox like PR’s can, would be a big help |
Beta Was this translation helpful? Give feedback.
-
Any update on this? I don’t see why delete protection must be a default for all branch protections. Can you not just have it as an extra tick box and let us decide whether we need this functionality? Eg. we might want to use branch protections only to enforce status checks for feature branches that need to be deleted after a PR. Currently, not even GitHub can delete those branches following a merged PR even if the Automatically delete head branches option is selected. |
Beta Was this translation helpful? Give feedback.
-
For those who join this thread late or who have been waiting, I checked my branch protection rules today and found the feature implemented! You can find the new force push and branch deletion rules at the bottom of the branch protection rule page for the branch name pattern you would like to apply rule to: |
Beta Was this translation helpful? Give feedback.
-
This is really a great addition |
Beta Was this translation helpful? Give feedback.
-
I dont see this aywhere, is this improvement not added in for Github enterprise? |
Beta Was this translation helpful? Give feedback.
-
The beginning of this post has a great suggestion
The existing feature in protection rules doesn't support that. There could be a use-case where not everyone who has write access to the branch should have delete access. It could be only admins having that access. So if the suggested feature could be implemented, it would be great. |
Beta Was this translation helpful? Give feedback.
-
If you do not wish to use the "allow deletions" option for users with push access, another way to get the desired behavior is to rename your branch after it has merged so that it no longer matches the branch protection rules. For example, if your branch was named "feat/super-cool-stuff" and your protection rule was "feat/*", once you have merged your branch and you are done with it, you can rename it to "merged/feat/super-cool-stuff" so that it no longer matches the branch protection rules, and then you can delete the branch. |
Beta Was this translation helpful? Give feedback.
For those who join this thread late or who have been waiting, I checked my branch protection rules today and found the feature implemented!
You can find the new force push and branch deletion rules at the bottom of the branch protection rule page for the branch name pattern you would like to apply rule to: