DEV Community

Luigui Moreno
Luigui Moreno

Posted on

Clean your git branches local and remote

Often after a few months of work I find myself with way too many git branches in my local repos, looking for in the internet how to delete local and remote branches in git, well, I have created a bash function for that, and now I'm goint to share it:

Add this to your bash profile

gitrm () { git branch -d $1 && git push origin :$1  }
gitrmf () { git branch -D $1 && git push origin :$1  }
Enter fullscreen mode Exit fullscreen mode

Usage:

gitrm fix/fix-this-breaks-that

To force delete local not merged branches

gitrmf feature/we-dont-even-need-his-feature-anymore

Discussion (0)