Alfonso's Website
1 min read time

List Recent GitHub Branches in Terminal

In this quick tutorial, we'll show you how to list the recent GitHub branches in your terminal using a simple command, and how to create an alias for that command to save time and streamline your workflow.

Listing Recent GitHub Branches

To list the 20 most recent branches in your local repository, enter the following command in your terminal:

git for-each-ref --count=20 --sort=-committerdate refs/heads/ --format='%(refname:short)'

This command will display the 20 most recent branches, sorted by the commit date in descending order.

Creating an Alias for the Command

To make the process even more efficient, you can create an alias for the command. Add the following line to your .bashrc, .zshrc, or other relevant shell configuration file:

alias rb="git for-each-ref --count=20 --sort=-committerdate refs/heads/ --format='%(refname:short)'"

After saving the changes to the configuration file, restart your terminal or run source ~/.bashrc, from now on you should be able to list your recent branches using the alias rb