DEV Community

Cover image for Cleaning up all local stale git branches
Leandro Cavalcante
Leandro Cavalcante

Posted on

1 1

Cleaning up all local stale git branches

Sometimes, after some great releases (e some broken ones), it's hard to maintain our repo tidy.

To help you dealing with the messy you made creating branches e pushing them away, I found a short command line that remove all local branches that were already merged.

Open your terminal and paste the commando below:

git fetch --prune | git branch -r | awk '{print $1}' | egrep -v -f /dev/fd/0 <(git branch -vv | grep origin) | awk '{print $1}' | xargs git branch -D
Enter fullscreen mode Exit fullscreen mode

It's also available as a Github Gist right here: https://gist.github.com/leandrocrs/428c956144b2b22738765d77e087a188.

Top comments (1)

Collapse
 
sr2ds profile image
David Silva •

Great article, thanks!

👋 Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay