See the Last 10 Branches You Worked On in Git
As part of my ongoing effort to become more effective at Git, I stumbled into an interesting problem. At Vimeo, we have a lot of branches named after issues reported in Jira. Some branches take on the name of the project or component or a very specific fix. We also have branches that don’t follow naming-conventions at all. It happens. Anyways, somedays, I forget the name of the branches I’ve worked on, say yesterday. Other times, I forgot what work I did on which branch. I grew tired of tab-switching between my terminal and Jira or Github to go and find my work history. I don’t need to see my commits, I just need to see a list of recent branches.
So, I began googling around the web, and came across this post. It’s a good solution I think, David Walsh seems to agree too. Basically, it lists the most recent branches you’ve worked on. But ideally, I’d rather opt for an alias in my
.bashrc. I don’t want to clutter up my
.gitconfig. That’s, just like my opinion man. Without further ado, here’s my alias in my
# ~/.bashrc alias recent-branches="git for-each-ref --sort=-committerdate --count=10 --format='%(refname:short)' refs/heads/"
Stupid simple, readable and short. Just the way I like it. There are of course, more complex solutions to this simple problem. But I’m not a huge fan of those longwinded solutions. Anyways, when I run the
recent-branches alias in my terminal:
➜ example-repo git:(feature-pages) recent-branches nav-bar-component-fix GH-48 features-pages FR-47 XR-73 VP-71 new-privacy-policy-page VP-70 VP-49 GH-46
Nifty huh? As you can see, the alias command is really just one long
git command. It takes a
count=10 flag. So if you need to see more branches in your history, just inflate the value accordingly. Enjoy! ✌️