Skip to content

Instantly share code, notes, and snippets.

@camertron
Created April 20, 2023 18:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save camertron/65d910a0df7eb47ef4f17da97e7e6c2d to your computer and use it in GitHub Desktop.
Save camertron/65d910a0df7eb47ef4f17da97e7e6c2d to your computer and use it in GitHub Desktop.
Interactive branch cleaner
# frozen_string_literal: true
branches = `git branch`.strip.split("\n").map(&:strip).reject { |b| b.start_with?("*") }
branches.each_with_index do |branch, idx|
STDOUT.write("[#{idx + 1}/#{branches.size}] Delete '#{branch}' (y/n)? ")
answer = gets
if answer.strip =~ /[yY]/
system("git branch -D #{branch}")
else
puts "Leaving '#{branch}' alone"
end
end
puts "Done! Thanks for playing."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment