Managing local git branches
April 17, 2020
Quick post alert!
Sometimes I end up working on multiple tasks at the same time. This usually means working with multiple branches at the same time or in the same sprint, etc.
To make it easier to switch context, I have this shell alias
set up to give an overview of all local branches:
alias grecent="git for-each-ref --sort=committerdate refs/heads/ --format='%(HEAD) \ %(color:yellow)%(refname:short)%(color:reset) \ - %(contents:subject) \ - (%(color:green)%(committerdate:relative)%(color:reset))'"
And here is what the output looks like in my test repo:
Note that the branches are sorted with most recently used one marked with an *
and at the bottom.
Each branch shows timestamp last edited and the last commit message so it’s easier to switch context between tasks.