Skip to content

Instantly share code, notes, and snippets.

@oggy
Created October 8, 2015 18:26
Show Gist options
  • Save oggy/cf24933ff8f194912240 to your computer and use it in GitHub Desktop.
Save oggy/cf24933ff8f194912240 to your computer and use it in GitHub Desktop.
Command to delete git branches that have been merged into the current branch
#!/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)
system 'git', 'branch', '-d', branch
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment