Bulk delete branches (BB-14660)

Issue #11941 open
Brett Field
created an issue

Is it possible to get some kind of branch manager?

We use Issue Branching(Feature Branching) and after some time there just sits tons of merged branches that now have to be deleted one at a time if you don't go through the Pull Request flow

Is it possible that nome cleanup tool can be make so that a bunch of branches can be deleted in one go?

Comments (11)

  1. Magnus Bondesson

    Johann - ok I see. If you don't wanna wait a couple of years before this issue is fixed you could do like I have done when we've been in similar situations, using one of these alternatives:

    If you happen to use JIRA and you've named your branches after JIRA issues you can do this to remove remote branches:

    1. Write all remote branches separated by a comma to a file
    git branch -a | grep XYZ- | sed 's/remotes\/origin\///' | sed -e :a -e '$!N; s/\n/,/; ta' > all_branches.txt
    
    1. Feed it to JIRA’s Issue Navigator listing all issues that aren’t resolved yet, using some filter, eg.
    project = XYZ AND status != Resolved AND issuekey in (content of all_branches.txt) ORDER BY key ASC
    
    1. Removed the non-resolved issues from all_branches.txt by search and replace
    2. Replaced all commas in all_branches.txt with spaces and ran
    git push origin –delete <content of all_branches.txt>
    

    If you don't name branches like that you could instead find out which branches have been merged to eg. master. With master checked out, run

    git branch -a --merged
    

    and delete those.

    I hope you got some ideas from this at least!

  2. Will Gibson

    We would really like to be able to press a button to "bulk delete all branches merged with <some_branch> (master as default) which have no commits in the last X days".

    It would be ace if this could be automated so it happens everyday too.

    Then we can just go through and manually tidy up the unmerged spike/abandonded branches.

  3. Tom Metcalfe

    Hi,

    I would really like to be able to bulk delete old branches if possible.

    Ideally something like 'Older than X days/months/years' or if they are not ahead of master.

    Cheers

    Tom

  4. Sarah Biddle

    +1 for this issue and I have a few more suggestions:

    View

    • Add a column with branch creator
    • Add a column with branch origin (eg. branced off from master, or from a hotfix branch)
    • Add a column with date of creation
    • Behind/ahead should show how the branch compares to the original branch, instead of comparing to whatever is selected in the drop-down in the upper left corner; this drop-down can be removed
    • Add check boxes
    • Add filter on: branch creator, branch origin, related pull request status (merged/open/etc)

    Management functionality

    • Enable user to multi-select branches
    • Add Remove button to remove the selected branches
  5. Log in to comment