Skip to content

Instantly share code, notes, and snippets.

@Theo6890
Created May 8, 2025 15:14
Show Gist options
  • Save Theo6890/ab8009a0960092fe2c85bcf442066e3a to your computer and use it in GitHub Desktop.
Save Theo6890/ab8009a0960092fe2c85bcf442066e3a to your computer and use it in GitHub Desktop.

List local stale branches:

git branch -vv | grep 'gone' | awk '{print $1}'

List and delete local stale branches

git branch -vv | grep "gone" | awk '{print $1}' | xargs git branch --delete



You could even create an alias on your machine. Modify ~/.gitignore (user level, not repo):

[alias]
    stale-local-branches = "!git branch -vv | grep 'gone' | awk '{print $1}'"
    delete-stale-local = "!git stale-local-branches | xargs git branch --delete"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment