Skip to main content
About>LabTalksPhotography
←Back to Lab

Cleaning up local branches

February 10, 20221 min read
  • snippet
  • git
  • bash
Edit on GitHub
blueskymastodongithublinkedin
© 2026 Koen van Gilst
v. 9.0.0 | 9dc8d1e
git branch -vv | grep ': gone]'|  grep -v "\*" | awk '{ print $1; }' | xargs -r git branch -d

Useful for cleaning up a local repository with lots of stale branches. The script can also be used with the -D flag (instead of -d). This will delete all local branches, even if they have any unmerged changes.