Created
June 5, 2014 18:30
-
-
Save oggy/bf96f1ffb762cd360431 to your computer and use it in GitHub Desktop.
Script to delete merged git branches, and preserve ones you care about
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 | |
keep = `git config git-delete-merged-branches.persist`.strip.split(',') | |
puts "preserving: #{keep.join(', ')}" | |
current_branch = `git rev-parse --abbrev-ref HEAD`.strip | |
`git branch --merged`.lines.each do |line| | |
next if line =~ /\A\* / | |
branch, target = line.strip.split(' -> ', 2) | |
next if keep.include?(branch) || keep.include?(target) | |
#puts "would kill: #{branch}" | |
system 'git', 'branch', '-d', branch | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment