Created
May 5, 2014 16:28
-
-
Save dgiunta/0bafa7439083c004a163 to your computer and use it in GitHub Desktop.
This little script uses the git-branch-report command but creates a report showing the commands to delete local branches that have already been merged into master.
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 | |
require 'optparse' | |
options = {} | |
OptionParser.new do |opts| | |
opts.banner = "Usage: git-safe-delete-branch-report [options]" | |
opts.on("--porcelain", "Output machine-readable output") do |v| | |
options[:porcelain] = v | |
end | |
end.parse! | |
safe_branches = `git-branch-report --porcelain`.split("\n").grep(/master/).reject {|l| | |
l =~ /^master/ | |
}.map {|l| l.split(":")[0] } | |
if options[:porcelain] | |
puts safe_branches.join("\n") | |
else | |
if safe_branches.length > 0 | |
puts "The following branches have been merged into master and thus are safe to delete:" | |
safe_branches.each do |branch| | |
puts <<-EOM | |
- #{branch} | |
git branch -D #{branch} | |
EOM | |
end | |
puts <<-EOM | |
Delete all branches with the following command: | |
git branch -D #{safe_branches.join(' ')} | |
EOM | |
else | |
puts "There are no branches that are safe to delete" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment