Skip to content

Instantly share code, notes, and snippets.

@ecavazos
Created February 19, 2012 04:02
Show Gist options
  • Save ecavazos/1861874 to your computer and use it in GitHub Desktop.
Save ecavazos/1861874 to your computer and use it in GitHub Desktop.
Delete local branches that have been merged into master.
#!/usr/bin/env ruby
branches = %x(git fetch origin && git branch --merged master)
exclude = /master|test|production|staging/
deletable = branches.split("\n").select { |branch| branch.strip !~ exclude }
if deletable.empty?
puts 'nothing to delete :('
else
deletable.each { |branch| p %x(git branch -d #{ branch.strip }) }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment