Skip to content

Instantly share code, notes, and snippets.

@7c00
Created November 27, 2024 07:27
Show Gist options
  • Save 7c00/68f6f243304f878082283295694be409 to your computer and use it in GitHub Desktop.
Save 7c00/68f6f243304f878082283295694be409 to your computer and use it in GitHub Desktop.
Select and delete git branches interactively. Take use of the power of gum.
#!/bin/bash
set -euo pipefail
branch_messages="$(git for-each-ref --format='%(refname:short) - %(contents:subject)' refs/heads/ | gum choose --header "Select branches to delete" --no-limit)"
branches="$(echo "$branch_messages" | awk -F' - ' '{print $1}')"
[[ -z "$branches" ]] && { echo "No branches selected" && exit 0; }
for branch in $branches; do
echo "Deleting branch: $branch"
git branch -D "$branch"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment