Skip to content

Instantly share code, notes, and snippets.

@bryanprimus
Created March 28, 2025 06:17
Show Gist options
  • Save bryanprimus/5e96e6c949cc1404141d7e5fa25b30a6 to your computer and use it in GitHub Desktop.
Save bryanprimus/5e96e6c949cc1404141d7e5fa25b30a6 to your computer and use it in GitHub Desktop.
gclb alias to clean git local branches and keep `development` as the only branch left
unalias gclb 2>/dev/null
gclb() {
git checkout development || return
local branches
branches=$(git branch --format="%(refname:short)" | grep -Fxv "development")
if [ -z "$branches" ]; then
echo $'\033[0;32mNo branches to be deleted.\033[0m'
return
fi
echo "Branches to be deleted:"
while IFS= read -r branch; do
echo $'\033[0;31m'"$branch"$'\033[0m'
done <<< "$branches"
read -q "confirm?Are you sure you want to delete these branches? (y/n): "
echo ""
if [[ $confirm =~ ^[Yy]$ ]]; then
echo "$branches" | xargs git branch -D
else
echo "Operation canceled."
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment