Created
February 23, 2012 21:02
-
-
Save xlymian/1895036 to your computer and use it in GitHub Desktop.
What branches can be pruned?
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 | |
# git_branch_prunable 0.1 - 2011-11-29 | |
# by Paul Mylchreest (paul.mylchreest@mac.com) | |
# | |
%x( git branch ).each_line do |branch| | |
branch.strip! | |
next if branch =~ /master|development|staging/ | |
cmd = "git log #{branch} -n 1 --pretty=oneline" | |
first_commit_line = %x( #{cmd} ) | |
commit_id = first_commit_line.match( /([0-9a-z]){40,40}/ )[0] | |
cmd = "git branch --contains #{commit_id}" | |
branches_containing = %x( #{cmd} ).lines.map{|x| x.strip!}. | |
reject{|x| x =~ /#{branch}/} | |
if branches_containing.size > 0 | |
puts "#{branch} is prunable!" | |
puts "branch: #{branch} commit => #{commit_id}" | |
if %x( git branch -r | grep #{branch} ).lines.count == 0 | |
puts "#{branch} has possibly no remote branch!" | |
puts "you may need to run: 'git branch -d #{branch}'" | |
else | |
puts "run: 'git push origin :#{branch}'" | |
puts "then: 'git branch -d #{branch}'" | |
end | |
puts '=' * 80 | |
end | |
end | |
puts "run: 'git remote prune origin' when done." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment