Skip to content

Instantly share code, notes, and snippets.

@fhwang
Created December 19, 2018 18:28
Show Gist options
  • Save fhwang/df623e283eb8a45254909070a2213028 to your computer and use it in GitHub Desktop.
Save fhwang/df623e283eb8a45254909070a2213028 to your computer and use it in GitHub Desktop.
A script for finding local branches that have not changed in X days.
#!/usr/bin/env ruby
unless ARGV.size == 1
puts "git-stale-branches [days ago]"
exit
end
require 'date'
days_ago = ARGV.first.to_i
branches = `git for-each-ref refs/heads --format='%(committerdate:raw) %(refname:short)'`
branches.each_line do |line|
line =~ /^(\d+) -\d+ (\S+)/
committerdatetime = Time.at($1.to_i)
committerdate = Date.new(
committerdatetime.year, committerdatetime.month, committerdatetime.day
)
branch_name = $2
puts branch_name if committerdate + days_ago <= Date.today
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment