DEV Community

Luigui Moreno
Luigui Moreno

Posted on

1

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

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay