Skip to content

Instantly share code, notes, and snippets.

Last active August 29, 2015 14:14
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
batch delete remote branches
#!/usr/bin/env ruby
abort 'please specify the remote to delete branches from' if ARGV.empty?
remote = ARGV.shift
puts "gathering list of branches for remote '#{remote}'"
branches = `git branch -r | grep #{remote}`.lines! { |s| s.strip! }
branches.reject! { |b| b =~ /.*\/master/ }
puts branches
printf '> proceed? '
ans = gets.chomp!
exit unless ans.upcase! == 'Y'
puts "ok, deleting #{branches.length} branches.."
branches.each do |b|
branch = b.gsub(/#{remote}\//, '')
cmd = "git push #{remote} :#{branch}"
puts cmd
system cmd
puts 'done.'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment