I have been using something like this for 10+ years by this point - still wonder why it is not default or easier to do than a custom gitconfig/alias hack. :P
asb 6 hours ago [-]
Even better (IMHO!) is `git config branch.sort -committerdate` (note the `-`). This will sort newest committer date first.
mmsc 3 hours ago [-]
`git config --global branch.sort -committerdate`
hsuduebc2 2 minutes ago [-]
Thanks!
nulltrace 2 hours ago [-]
Rebase an old branch and it suddenly looks recent again. The rewritten tip gets a fresh committer date.
quuxplusone 2 hours ago [-]
Yes. This is what one wants, since if you have recently rebased it, you're clearly doing work with it. Meanwhile, branches you don't care to touch sink to the bottom of the list.
johnwheeler 55 minutes ago [-]
Even better, "hey, chat GPT, list my branches by commit date."
I know that's not a popular answer, but I'm just trying to demonstrate the reality that this kind of knowledge isn't specialized anymore.
hsuduebc2 54 seconds ago [-]
Heh. "Just Google it" answers we're never particular conversation lubricant as they are not now. But of course you are right we live in age of wonder once again.
pkaodev 6 hours ago [-]
I have this as an alias in my .zshrc!! Very handy
cryptolobster 12 minutes ago [-]
TIL Git can do this without a shell script. I’ve been manually sorting through branches like an idiot
Nice. Will help solve some mysteries on older projects.
ComputerGuru 5 hours ago [-]
FYI/fwiw Fish shell autocompletes branches sorted by last commit date when writing out git commands. It also provides completions for commitish objects grouped by class, giving precedence to the usual targets first, with each group sorted by its own sort key. Handy!
dalton74 1 hours ago [-]
Our team's `git branch` output is a graveyard. Sorting by last commit would be a godsend for quickly identifying active work and stale branches.
It opens a fuzzy finder window showing the branches you have in the repo, sorted by recency. Also shows the latest committer and the date. Hit enter on the one you want to swap to it.
zahlman 5 hours ago [-]
How many branches would you need to have to make this worthwhile?
jamietanna 5 hours ago [-]
At any time I'm working across 5-30 branches (some when I'm reviewing other folks' code) so it's handy to see my latest branches
spike021 3 hours ago [-]
At my current job it's fairly frequent that I have 5+ active branches open for a repo. Not ideal and that's another topic, but it is nice to be able to sort branches because of that.
woodruffw 4 hours ago [-]
I've seen monorepos with over 10k active branches. But even at a smaller scale (10-100 branches), it becomes useful when manually stacking and/or rebasing, especially if you have a smaller terminal.
mcdow 2 hours ago [-]
yep, i have a little helper in my zshrc for this sort of thing:
alias git-hot-refs="git branch --sort=committerdate | tail"
tikhonj 45 minutes ago [-]
Let's sort git branches by quality, better branches towards the top, slop at the bottom.
monster_truck 4 hours ago [-]
I just click on tower and open it, much better
bewareofscams 5 hours ago [-]
Or just have `jj log` custom-configured.
woodruffw 4 hours ago [-]
Another useful one if you have a large number of tags and want to see the most recently created ones first:
git config --global tag.sort -creatordate
(`-creatordate` reverses the sort so that the newest come first.)
jeffbee 2 hours ago [-]
Feels like the type of problem you could simply choose to not have in the first place (by not using git).
Rendered at 01:21:13 GMT+0000 (Coordinated Universal Time) with Vercel.
I know that's not a popular answer, but I'm just trying to demonstrate the reality that this kind of knowledge isn't specialized anymore.
[0] - https://github.com/paulirish/git-recent
It opens a fuzzy finder window showing the branches you have in the repo, sorted by recency. Also shows the latest committer and the date. Hit enter on the one you want to swap to it.
alias git-hot-refs="git branch --sort=committerdate | tail"