Cleaning up all local stale git branches
Leandro Cavalcante
Posted on July 13, 2022
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
It's also available as a Github Gist right here: https://gist.github.com/leandrocrs/428c956144b2b22738765d77e087a188.
💖 💪 🙅 🚩
Leandro Cavalcante
Posted on July 13, 2022
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.