Created
October 14, 2013 16:23
-
-
Save tcrayford/6978272 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby -wKU | |
# encoding: UTF-8 | |
# prints out the last 15 git branches you used | |
reflog = IO.popen('git reflog') | |
$branches = [] | |
def add_branch(b) | |
$branches << b unless $branches.include? b | |
end | |
all_branches = IO.popen('git branch').readlines.map { |x| x.gsub('* ', '').strip } | |
reflog.readlines.each do |line| | |
if line.match(/moving from (\S+) to (\S+)/) | |
add_branch($1) if all_branches.include? $1 | |
add_branch($2) if all_branches.include? $2 | |
end | |
break if $branches.size > 15 | |
end | |
puts "* #{$branches[0]}" | |
$branches.drop(1).each { |b| puts b } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment