Created
July 15, 2013 02:02
-
-
Save jish/5997030 to your computer and use it in GitHub Desktop.
Branch cleanup. Made this a private gist to begin with, but people keep asking me for a link to it. Horray for open source! (:
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 | |
puts "Starting..." | |
branches = `git branch --merged`.split("\n").map { |branch| branch.strip } | |
pattern = (ARGV.shift || `whoami`).strip | |
branches.select! { |branch| branch.match(pattern) } | |
count = branches.size | |
puts "Deleting #{count} branches..." | |
branches.each do |branch| | |
if system("git branch -d #{branch}") | |
# Check if there is a remote branch present | |
if system("git branch -a | grep origin/#{branch}") | |
system("git push origin :#{branch}") | |
end | |
count = count - 1 | |
puts "deleted. (#{count} left)" | |
else | |
abort "FAILED TO DELETE #{branch}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Maybe add
'git fetch && git remote prune origin` at line 4?