Skip to content

Instantly share code, notes, and snippets.

@Kallin
Created October 17, 2018 21:52
Show Gist options
  • Save Kallin/bdbbba6edb07b6e906864159ef9184b8 to your computer and use it in GitHub Desktop.
Save Kallin/bdbbba6edb07b6e906864159ef9184b8 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
current_branch = `git symbolic-ref --short HEAD`.chomp
if current_branch != "master"
if $?.exitstatus == 0
puts "WARNING: You are on branch #{current_branch}, NOT master."
else
puts "WARNING: You are not on a branch"
end
puts
end
local_branches= `git branch --merged`.
gsub(/^\* /, '').
split("\n").
map(&:strip).
reject {|b| b =~ /(#{current_branch}|master)/}
if local_branches.empty?
puts "No existing branches have been merged into #{current_branch}."
else
puts "This will remove the following branches:"
puts local_branches.join("\n")
puts "Proceed?"
if gets =~ /^y/i
`git branch -d #{local_branches.join(' ')}`
else
puts "No branches removed."
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment