Skip to main content
Koen van Gilst
AboutLabTalksPhotography
←Back to Lab

Cleaning up local branches

February 10, 2022

1 min read

  • snippet
  • git
  • bash
Edit on GitHub
blueskymastodongithublinkedin
© 2026 Koen van Gilst
v. 9.0.0 | 299bb3d
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.