Skip to content

Instantly share code, notes, and snippets.

@t27duck
Created December 21, 2017 14:01
Show Gist options
  • Save t27duck/5010ae0e8d1c2fc760f539b451841b8e to your computer and use it in GitHub Desktop.
Save t27duck/5010ae0e8d1c2fc760f539b451841b8e to your computer and use it in GitHub Desktop.
Deletes local branches that have been merged into master
branch_prefix = "pt_"
branches_to_keep = []
cmd = `git branch --merged master`
branches = cmd.split("\n").map(&:strip).select{ |b| b.start_with?(branch_prefix) && !branches_to_keep.include?(b) }
branches.each do |branch|
`git branch -D #{branch}`
end
@mwagz
Copy link

mwagz commented Dec 21, 2017

Without the prefix, maybe?

branches_to_keep = []
cmd = `git branch --merged master`
branches = cmd.split("\n").map(&:strip).select{ |b| !branches_to_keep.include?(b) }
branches.each do |branch|
  `git branch -D #{branch}`
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment