git branch --sort=-committerdate -v
It gives me the following output (first line for not actually included): [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 git for-each-ref --sort=-committerdate --format='%(committerdate:short): %(refname:short)' refs/heads/
Including the dates is crucial; I'll frequently go in and clean up personal branches that are older than X months. git for-each-ref --sort=-committerdate refs/heads/ --format='%(refname:short) %(committerdate:short) %(upstream:remoteref)' | column -t git branch -a --sort=-committerdate
That's short enough for my taste not to have to alias, and it gives output more or less similar to GitHub's "Active branches" view.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.
Maybe someone will find it useful as I have.
https://news.ycombinator.com/item?id=22797911
And for those wondering "deleted branches?", check the git-gc man page for gc.reflogexpire (default 90 days) and gc.reflogexpireunreachable (default 30 days).
https://github.com/kbd/setup/blob/f3ebd5ef2bc8a010357b574c02...
[alias] rb = for-each-ref --sort=-committerdate --format='%(refname:short)' refs/heads/ --count=10
To switch branches, I invoke this from a shell script and type a couple characters from a branch name
git checkout (git rb|fzf)
git for-each-ref
--sort=-committerdate
--format='%(committerdate:short) %(refname:short) %(objectname:short) %(contents:subject)'
refs/heads/
The output shows the date, branch name, commit hash, and commit subject, such as: 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
I put my aliases in GitAlias, which has many more: https://github.com/gitalias/gitaliashttps://github.com/bhaak/dotfiles/blob/master/git/git-overvi...
It has been so useful to me that I think I should extract it from my dotfiles repository and give it its own repository.
Or reimplement it in Rust as a introductory programming project.
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.
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))'"
https://github.com/whalesalad/dotfiles/blob/master/zsh/git.z...
The most recent branches will appear closest to your cursor (on the bottom).
git log --all --author=`git config user.email` --oneline --decorate