Sha256: 835113d008992c09c17ee72131a77aeb3a2f392874064191b4d3a28044c1d338

Contents?: true

Size: 1.01 KB

Versions: 6

Compression:

Stored size: 1.01 KB

Contents

#!/usr/bin/env ruby
require 'optparse'

# Deletes (almost) every branch already merged into current branch.
# Exceptions are `master`, `staging`, and `development`, and the current
# branch, which are preserved. We also support custom configuration via the
# `~/.git-cleanup-preserved` file.

options = {}
OptionParser.new do |opts|
  opts.banner = "Usage: git cleanup [options]"

  opts.on("-r", "Clean up remote branches") do
    options[:remote] = true
  end
end.parse!

preserved = "master|staging|development"
preserved_file = File.join(Dir.home, '.git-cleanup-preserved')
if File.exist?(preserved_file)
  additional_preserved = File.read(preserved_file).strip.split("\n")
  unless additional_preserved.empty?
    preserved += '|' + additional_preserved.join('|')
  end
end
cmd  = %(git branch --merged | grep -v "\*" | egrep -v "(#{preserved})" | )
if options[:remote]
  cmd += "sed -e 's/origin\\//:/' | xargs git push origin"
  cmd.sub!('git branch', 'git branch -r')
else
  cmd += 'xargs -n 1 git branch -d'
end
system cmd

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
git-utils-2.1.0 bin/git-cleanup
git-utils-2.0.0 bin/git-cleanup
git-utils-1.0.0 bin/git-cleanup
git-utils-0.7.1 bin/git-cleanup
git-utils-0.7.0 bin/git-cleanup
git-utils-0.6.5 bin/git-cleanup