Sha256: ca399204c1809f983dd18a608210d189ce6de4f66d4dabb504e2b2feb27ed45a
Contents?: true
Size: 1.02 KB
Versions: 1
Compression:
Stored size: 1.02 KB
Contents
#!/usr/bin/env ruby require 'optparse' # Deletes (almost) every branch already merged into current branch. # Exceptions are `master`, `main`, `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|main|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
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
git-utils-2.2.0 | bin/git-cleanup |