Skip to content

Instantly share code, notes, and snippets.

@tijn
Created January 4, 2017 21:18
Show Gist options
  • Save tijn/ed0d36248340b5719fa7accb52be4a31 to your computer and use it in GitHub Desktop.
Save tijn/ed0d36248340b5719fa7accb52be4a31 to your computer and use it in GitHub Desktop.
remove merged branches; could be generalized and cleaned up but it's already useful in its current form
#!/usr/bin/env ruby
if ARGV.include? '--help'
puts "git-scrub"
puts
puts "Remove all merged and stale branches."
puts
puts " merged = merged into master (the command will only run on the master branch)"
puts " stale = removed from the remote"
exit 0
end
current_branch = `git rev-parse --abbrev-ref HEAD`.strip
if current_branch != 'master'
STDERR.puts 'not on master branch'
exit 1
end
merged = `git branch --merged | grep -v 'master'`.split
merged.each do |branch|
STDERR.puts branch
`git branch -d "#{branch}"`
end
`git remote prune origin`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment