DEV Community

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

Posted on

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:

Top comments (1)

sr2ds profile image
David Silva

Great article, thanks!