Skip to content

Instantly share code, notes, and snippets.

@Sundwell
Created December 14, 2025 10:33
Show Gist options
  • Select an option

  • Save Sundwell/3419645067681d66d761b35677e61de7 to your computer and use it in GitHub Desktop.

Select an option

Save Sundwell/3419645067681d66d761b35677e61de7 to your computer and use it in GitHub Desktop.
Clear all deletable git branches
git fetch -p && \
default_branch="$(git symbolic-ref --quiet --short refs/remotes/origin/HEAD | sed 's@^origin/@@' || echo main)" && \
current_branch="$(git branch --show-current)" && \
git branch --merged "origin/$default_branch" --format='%(refname:short)' \
| grep -vE "^(${default_branch}|${current_branch})$" \
| xargs -r git branch -d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment