I alias 'git recent' to:<p><pre><code> git branch --sort=-committerdate -v
</code></pre>
It gives me the following output (first line for not actually included):<p><pre><code> [branch name] [hash] [commit message header]
move-radio-and-checkbox-hints-up 9dff690 Move the hints belonging to radios/checkboxes up
update-rubocop 8cace1f Update rubocop and pry, fix some new offences
fix-remaining-injected-content-placement 48dc51d Reorder elements of other inputs</code></pre>
So many commenters here providing alternatives seem to miss the key differentiating feature: recently checked out vs. recently committed to. For me the former is immensely more useful as I may have gone to a branch to do something other than commit, and those are missed with the latter.<p>Anyway, I’ve had my own (far more involved) version of listing recently checked-out branches for years. It will also filter out the current branch and deleted branches, and has a rudimentary interactive selection.<p>Maybe someone will find it useful as I have.<p><a href="https://github.com/amarshall/git-recent-branches" rel="nofollow">https://github.com/amarshall/git-recent-branches</a>
I shared this with a coworker, who discovered that it dumps information about branches that don't exist anymore. This comment's alternate command doesn't list deleted branches:<p><a href="https://news.ycombinator.com/item?id=22797911" rel="nofollow">https://news.ycombinator.com/item?id=22797911</a><p>And for those wondering "deleted branches?", check the git-gc man page for gc.reflogexpire (default 90 days) and gc.reflogexpireunreachable (default 30 days).
Even better, show your local/remote branches in most-recent order and interactively pick the branch to switch to using fzf:<p><a href="https://github.com/kbd/setup/blob/f3ebd5ef2bc8a010357b574c02ecf5f8f1c2886a/HOME/.config/git/config#L67" rel="nofollow">https://github.com/kbd/setup/blob/f3ebd5ef2bc8a010357b574c02...</a>
I alias `git ref-recent` to:<p><pre><code> git for-each-ref
--sort=-committerdate
--format='%(committerdate:short) %(refname:short) %(objectname:short) %(contents:subject)'
refs/heads/
</code></pre>
The output shows the date, branch name, commit hash, and commit subject, such as:<p><pre><code> 2020-04-06 master d8560f4 Add feature foo
2020-03-28 fix-button 15f985d Fix button for menu
2020-03-19 optimize-sort 3dbec4d Optimize sort algorithm
</code></pre>
I put my aliases in GitAlias, which has many more: <a href="https://github.com/gitalias/gitalias" rel="nofollow">https://github.com/gitalias/gitalias</a>
I made a small script that outputs local and/or remote branches color coded: <a href="https://i.imgur.com/QkmPhm0.png" rel="nofollow">https://i.imgur.com/QkmPhm0.png</a><p><a href="https://github.com/bhaak/dotfiles/blob/master/git/git-overview-branches" rel="nofollow">https://github.com/bhaak/dotfiles/blob/master/git/git-overvi...</a><p>It has been so useful to me that I think I should extract it from my dotfiles repository and give it its own repository.<p>Or reimplement it in Rust as a introductory programming project.
I had idea to add something similar as tab completion to posh-git module for Powershell. Sadly it was not merged (is posh-git dead?) <a href="https://github.com/dahlbyk/posh-git/pull/641" rel="nofollow">https://github.com/dahlbyk/posh-git/pull/641</a><p>I wonder if something similar can be done in bash? By default bash doesn't "cycle" through possible completion but just display the list. Still, I guess it would be usefull to display last used branches first.
Neat! This was a feature I requested in Fork[0], but wasn't sure such a thing was even possible.<p>[0] <a href="https://git-fork.com" rel="nofollow">https://git-fork.com</a>
I alias `gbv` to this which shows you commit hash, msg, ID, author, date with colors:<p>alias gbv="git for-each-ref --sort=committerdate refs/heads/ --format='%(HEAD) %(color:yellow)%(refname:short)%(color:reset) - %(color:red)%(objec tname:short)%(color:reset) - %(contents:subject) - %(authorname) (%(color:green)%(committerdate:relative)%(color:reset))'"
I’ve got something similar, but it’s color coded and has columns with more info.<p><a href="https://github.com/whalesalad/dotfiles/blob/master/zsh/git.zsh#L12" rel="nofollow">https://github.com/whalesalad/dotfiles/blob/master/zsh/git.z...</a>
I use this:
git for-each-ref --sort=authordate --format '%(authordate:iso) %(align:left,25)%(refname:short)%(end) %(subject)' refs/heads<p>The most recent branches will appear closest to your cursor (on the bottom).
Been using this snippet from Paul Irish for years: <a href="https://github.com/paulirish/git-recent" rel="nofollow">https://github.com/paulirish/git-recent</a>