Feature: Delete branches not associated to open merge request
Release notes
Title: Add a "Delete orphan branches" action
Description: Quickly clean up your repository branches by deleting all branches not associated to any open merge-request with respect to "Protected branches" rules
Problem to solve
GitLab git repositories tend to contain a lot of stale branches. Most of the time those branches are just "dead branches", which means they do not include any valuable code.
Those branches can bloat the search results, may have performance implications (I think) and may later conflicts with new branch creation attempts.
Those branches may come from different sources:
- Closed merge requests (this does not delete the branch)
- Developer pushed branch for backup
- Developer pushed branch by mistake
- Merged merge request without the "delete branch" option selected (can be deleted using the "Delete merged branches" action if there were no squash)
The idea is to give a tool for the user to cleanup those "dead branches".
Note: https://gitlab.com/gitlab-org/gitlab/-/branches/all has more than 15_000 branches, some of them without any activity for 7 years.
Proposal
- In the branches view (https://gitlab.com/gitlab-org/gitlab/-/branches), add a "Delete orphan branches" to the dropdown menu:
- On click open a modal (like the "Delete merged branches" one):
- When the user clicks on "Delete orphan branches" (after typing "delete"), display a toast message:
- In background:
- Identify all branches that are not associated to any open merge request and not protected by any branch protection rule
- For each branch, delete it
Intended users
Feature Usage Metrics
We can track the usage with:
- Number of clicks to on the "Delete orphan branches" action button
- Number of submission to deletion using the modal
- Number of deleted branches using this feature
Does this feature require an audit event?
I'm not sure. I would say it is relevant to know if someone used this feature as to diagnose potential "code loss".
Furthermore, I would still expect this to be rather easy to recover from, as most of the developers should still have their branches in local.
Unresolved questions
-
How to name the dropdown entry ? (Suggested: "Delete orphan branches") -
Should the user be able to preview which branches will get deleted (this is currently not the case with the "Delete merged branches" action) ? -
Should the user receives an e-mail once the process is done with the deleted branches names ? -
Should the branch view include an icon to easily identify if a branch is linked to an open merge request (even if it does not target the default branch or if it is a target) ? => Already the case on gitlab.com