Created
December 9, 2011 21:26
-
-
Save xlymian/1453368 to your computer and use it in GitHub Desktop.
git-prunable-branches
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}" | |
puts "#{branches_containing}" | |
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}'" | |
end | |
puts "run: 'git push origin :#{branch}'" | |
puts "then: 'git branch -d #{branch}'" | |
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