Listing your most recently used git branches
Someone shared this article recently, and I thought it was pretty neat.
List your most recently-used branches using Git by Scott Stafford
Set up a git alias that uses the reflog to show what branches you have most recently been using.
But there was one small detail I couldn’t get past. See if you can spot it in the sample below.
1 day ago: add-categories-to-store-home
7 days ago: master
7 days ago: cancellation-improvements
7 days ago: add-phone-number
8 days ago: show-banner-for-unpaid-orders
12 days ago: add-order-address-update
Yep, the alignment of each branch name is all off, and it makes it more difficult to scan.
The fix, thankfully, was simple. All that needed to be done was to add a \t
to the output.
1 days ago: add-categories-to-store-home
7 days ago: master
7 days ago: cancellation-improvements
7 days ago: add-phone-number
8 days ago: show-banner-for-unpaid-orders
12 days ago: add-order-address-update
So the new command is:
lb = !git reflog show --pretty=format:'%gs ~ %gd' --date=relative | grep 'checkout:' | grep -oE '[^ ]+ ~ .*' | awk -F~ '!seen[$1]++' | head -n 10 | awk -F' ~ HEAD@{' '{printf(\" \\033[33m%s:\t \\033[37m %s\\033[0m\\n\", substr($2, 1, length($2)-1), $1)}'
A tad unwieldy, yes. But I don’t think I’ll need to change it for a while.
Enjoy your tabularly aligned output!