Created
November 27, 2024 07:27
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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