Last active
August 29, 2015 14:14
-
-
Save ellemenno/01740adc231e6637668a to your computer and use it in GitHub Desktop.
batch delete remote branches
This file contains 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
#!/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