TIL: Clean up local branches

Photo by JESHOOTS.COM on Unsplash

TIL: Clean up local branches

Pau Riosa's photo
Pau Riosa
ยทFeb 3, 2022

Today I learned how to clean up local branches that no longer have references to the remote (have already been merged/shipeed/etc). Thanks to one my work mates Moshe Paul, Backend Engineer at Papa.

$ 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

Happy Coding!

Share this