27

Using Intellij IDE (I have version 2017.3.5) is there a way to delete multiple local git branches at once

Marquis Blount
  • 5,716
  • 5
  • 32
  • 60

4 Answers4

29

You can delete multiple branches in IntelliJ IDEA directly.

Go to tab Git / Log. There open the Tree view on the left side. Check this picture:

enter image description here

Source: https://youtrack.jetbrains.com/issue/IDEA-131571

mojmir.novak
  • 1,346
  • 19
  • 28
21

// Update Feb 2021:

As mojmir.novak pointed out here: https://stackoverflow.com/a/65954247/1546042 you can do this now in IntelliJ. To remove only merged branches, see answer below:

// Older update:

To clean-up (old) feature branches that have been merged to master you can use the terminal to clean it up.

To delete all local branches that are already merged into the currently checked out branch:

git branch --merged | egrep -v "(^\*|master|dev)" | xargs git branch -d

See https://stackoverflow.com/a/6127884/1546042 for more details.

Cleaning up using run config"

In order to clean up multiple branches at once, using intelliJ. You need to install the Bash Support plugin and use it to create a run config that executes a script with the above command.

  1. Install BashSupport plugin
  2. Create script with the command. (e.g. ~/scripts/clean-branches.sh)
  3. Create a new Bash run config.
  4. Link to the script created in step #2.
  5. Provide working directory of the repo you want to clean.
  6. Run it to clean the branches.
Pim Hazebroek
  • 3,135
  • 1
  • 21
  • 33
  • 1
    I create a branch for each change i make; after time this quickly piles up. Intellij provides a way to delete individual local (and remote) branches. so i was curious if there was a way to do select multiple and delete – Marquis Blount May 02 '18 at 07:33
  • I suspected as such, as I've found myself in the same position :-) See updated answer. – Pim Hazebroek May 02 '18 at 07:35
  • 1
    @MarquisBlount see new update, I've found a way to "automate" it with IntelliJ using the BashSupport plugin. – Pim Hazebroek May 02 '18 at 07:55
  • 1
    @MarquisBlount did you file a feature request? Might be helpful to add the URL here so people can vote on it. I want this too! – jon_wu Jun 14 '19 at 17:13
  • @jon_wu sorry, no I never got around to it – Marquis Blount Jun 14 '19 at 22:58
15

There is a Plugin available for this:

https://plugins.jetbrains.com/plugin/10059-git-branch-cleaner/

To use it once it's installed, in the main menu go to:

VCS > Git > Delete Old Branches

IOIIOOIO
  • 2,197
  • 2
  • 9
  • 19
0

Have been through the pain of cleaning up the unused branches, and found this plugin.

https://plugins.jetbrains.com/plugin/10059-git-branch-cleaner/

But I was not able to see the VCS > Git menu on my Mac - IntelliJ VCS > Git - not found

But was successful in finding a similar option under git > context-menu - Delete old branches...

Git - Context menu - delete old branches

I am not sure if there is a default option or this is because of the above-mentioned plugin.

Sharing to help others who don't have VCS > Git menu like in my case

Praveen
  • 1,199
  • 1
  • 10
  • 20