Skip to content

Instantly share code, notes, and snippets.

@ellemenno
Last active August 29, 2015 14:14
Show Gist options
  • Save ellemenno/01740adc231e6637668a to your computer and use it in GitHub Desktop.
Save ellemenno/01740adc231e6637668a to your computer and use it in GitHub Desktop.
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
branches.map! { |s| s.strip! }
branches.reject! { |b| b =~ /.*\/master/ }
branches.join("\n")
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
end
puts 'done.'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment