Skip to content

Instantly share code, notes, and snippets.

@stuartnelson3
Created June 10, 2013 19:30
Show Gist options
  • Save stuartnelson3/5751507 to your computer and use it in GitHub Desktop.
Save stuartnelson3/5751507 to your computer and use it in GitHub Desktop.
set file to executable and drop in /usr/local/bin/
#!/usr/bin/env ruby
require 'date'
commit_branches_and_dates = `git for-each-ref --sort=-committerdate refs/heads/ --format='%(refname) %(committerdate)'`.split("\n").map {|e| e[11..-1] }.map {|e| e.split(' ', 2) }
one_month_in_seconds = 60*60*24*30
parsable_time = (Time.now - one_month_in_seconds).to_s
one_month_before_now = Date.parse(parsable_time)
deleted_branch_count = 0
commit_branches_and_dates.each do |branch, date|
date = Date.parse date
# delete branches that haven't had a commit in more than a month
if date < one_month_before_now
deleted_branch_count += 1
puts "deleting #{branch} from #{date}"
`git branch -D #{branch}`
end
end
puts "finished deleting branches", "#{deleted_branch_count} removed"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment