Skip to content

Instantly share code, notes, and snippets.

@oggy
Created June 5, 2014 18:30
Show Gist options
  • Save oggy/bf96f1ffb762cd360431 to your computer and use it in GitHub Desktop.
Save oggy/bf96f1ffb762cd360431 to your computer and use it in GitHub Desktop.
Script to delete merged git branches, and preserve ones you care about
#!/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