Skip to content

Instantly share code, notes, and snippets.

@levity
Created January 10, 2013 00:48
Show Gist options
  • Save levity/4498428 to your computer and use it in GitHub Desktop.
Save levity/4498428 to your computer and use it in GitHub Desktop.
list remote branches sorted by age
require 'date'
branch_times = `git remote show origin`.split("\n").grep(/tracked/).map do |line|
name = line.split(' ').first
last_log = `git log -n1 origin/#{name}`
last_time = Date.parse(last_log.split("\n").grep(/^Date/).first.sub(/^Date\s+/, ''))
[name, last_time.to_date]
end.sort_by(&:last)
branch_name_maxlen = branch_times.map(&:first).map(&:size).max
branch_times.each do |name, date|
puts "%-#{branch_name_maxlen}s #{date}" % name
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment