Back to the posts

How to clean local git branches

After working on some projects, my github repository ended up having many branches locally because PR is usually merged in GitHub.

To clean up old branches, I run the following.

EDITOR='code -w'
git branch -v > /tmp/branches.txt &&
  eval $EDITOR /tmp/branches.txt &&
  cat /tmp/branches.txt | cut -d' ' -f3 | xargs git branch -D

© 2021 Mo Kweon. All rights reserved.