loading...
Cover image for How to clean up git branches in a sweep

How to clean up git branches in a sweep

assertnotnull profile image Patrice Gauthier ใƒป1 min read

You have been working a while and have created a lot branches. They are piling up. You forgot about them but they impede your productivity.
You want to push your branch but the autocomplete in terminal is stopping at the last character because it can't guess which branch you mean.

You have too much branches locally.

I have a simple trick to that allows you to delete many branches at once while selecting which one using the NPM project ipt

First install it by doing

npm i -g ipt

Now in the repo you want to delete branches do:

git branches|ipt -m|xargs -I{} git branch -d {}

or -D {} to force delete.

console

The above first list all the branches piping the list to ipt (with the select multiple option) then a list of the selected will be piped to xargs that will do a git branch -d <branch> which will delete each branch ๐ŸŽ‰

Bonus: Using the git extension of ohmyzsh

gb|ipt -m|xargs -I{} git branch -d {}

sadly using aliases (gb) doesn't work with xargs.

Thats'all!

Discussion

pic
Editor guide