Created
July 28, 2015 05:35
-
-
Save kaikoga/d0b7c45981ccc31d7fe7 to your computer and use it in GitHub Desktop.
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 | |
force = ARGV.include? "-f" | |
current_branch = `git symbolic-ref --short HEAD`.chomp | |
remote_branches = `git branch -r --list`. | |
split("\n"). | |
map(&:strip). | |
map{|a|a.split("/")[1..-1].join("/")} | |
local_branches = `git branch --list --merged`. | |
gsub(/^\* /, ''). | |
split("\n"). | |
map(&:strip) | |
merged_branches = local_branches - remote_branches - [current_branch] | |
if merged_branches.empty? | |
puts "No existing local branches have been merged into #{current_branch}." | |
else | |
puts "Local branches merged into #{current_branch} found:" | |
puts merged_branches.join("\n") | |
puts "Remove branches? (y/N)" | |
if force || gets =~ /^y/i | |
# Remove local branches | |
`git branch -d #{merged_branches.join(' ')}` | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment