Skip to content

Instantly share code, notes, and snippets.

@kaikoga
Created July 28, 2015 05:35
Show Gist options
  • Save kaikoga/d0b7c45981ccc31d7fe7 to your computer and use it in GitHub Desktop.
Save kaikoga/d0b7c45981ccc31d7fe7 to your computer and use it in GitHub Desktop.
#!/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