Skip to content

Instantly share code, notes, and snippets.

@palashmon
Created February 19, 2024 08:30
Show Gist options
  • Save palashmon/4ada134842b08a604ffd09f3f31b128f to your computer and use it in GitHub Desktop.
Save palashmon/4ada134842b08a604ffd09f3f31b128f to your computer and use it in GitHub Desktop.
Display A List Of Git Branches Ordered By Most Recent Commits

Display A List Of Git Branches Ordered By Most Recent Commits

This file provides commands to display a list of Git branches ordered by the 20 most recent commits, both locally and including remote branches. These commands are helpful for developers to easily track recent activity in the repository.

Show Local Git Branches

To view a list of local Git branches sorted by commit date, use the following command:

git for-each-ref --count=20 --sort=-committerdate refs/heads --format='%(authordate:short) %(color:red)%(objectname:short) %(color:yellow)%(refname:short)%(color:reset) (%(color:green)%(committerdate:relative)%(color:reset))'

This command retrieves the 20 most recent branches and displays them along with their commit dates, commit hashes, and branch names, sorted in descending order by default. To sort the branches in ascending order, simply remove the - sign before committerdate in the command.

Show Local and Remote Git Branches

To display both local and remote Git branches sorted by commit date, execute the following command:

git for-each-ref --count=20 --sort=-committerdate refs/heads refs/remotes --format="%(authordate:short) %(color:red)%(objectname:short) %(color:yellow)%(refname:short)%(color:reset) (%(color:green)%(committerdate:relative)%(color:reset)) %(authorname)"

This command retrieves the 20 most recent branches from both local and remote repositories, providing information on commit dates, commit hashes, branch names, and author names.

Feel free to utilize these commands to stay up-to-date with the latest developments in your Git repository!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment