Sha256: 18c10482a864357686d8874f2b53fbfc24c17c6f8782d59d3ad1d7744684e9e1
Contents?: true
Size: 1.03 KB
Versions: 3
Compression:
Stored size: 1.03 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}|HEAD)" | ) 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
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
git-utils-2.4.0 | bin/git-cleanup |
git-utils-2.3.0 | bin/git-cleanup |
git-utils-2.2.1 | bin/git-cleanup |