Skip to content

Instantly share code, notes, and snippets.

@dgiunta
Created May 5, 2014 16:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dgiunta/cc2542e2a6dcc2aec2d7 to your computer and use it in GitHub Desktop.
Save dgiunta/cc2542e2a6dcc2aec2d7 to your computer and use it in GitHub Desktop.
This little script essentially spits out a nicely formatted report from running git branch --contains <branch> on your local repository. You might use this script if you wanted to see which branches have been merged into master already.
#!/usr/bin/env ruby
require 'optparse'
options = {}
OptionParser.new do |opts|
opts.banner = "Usage: git-branch-report [options]"
opts.on("--porcelain", "Output machine-readable output") do |v|
options[:porcelain] = v
end
opts.on_tail("-h", "--help", "Show this message") do
puts opts
exit
end
end.parse!
branches = `git branch | sed -e "s/[\* ]*//"`.split("\n")
containing_branches = branches.inject({}) do |ret, branch|
ret[branch] = `git branch --contains "#{branch}" | sed -e "s/[\* ]*//"`.split("\n")
ret
end
if options[:porcelain]
containing_branches.each do |branch, branches|
puts "#{branch}: #{branches.join(" ")}"
end
else
puts "Branch Report"
containing_branches.each do |branch, branches|
puts <<-EOM
#{branch}:
-- #{branches.join("\n -- ")}
EOM
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment