Sort branches by last commit date
104 points - last Tuesday at 2:57 PM
SourceComments
jbranchaud today at 12:49 AM
The best upgrade to these kinds of git branch scripts is piping them to fzf. Iβve been using this fbr one from the fzf repo. https://github.com/jbranchaud/dotfiles/blob/main/zshrc.local...
asb yesterday at 7:43 PM
Even better (IMHO!) is `git config branch.sort -committerdate` (note the `-`). This will sort newest committer date first.
rmunn today at 2:13 AM
I have been using the `git lb` alias suggested by https://ses4j.github.io/2020/04/01/git-alias-recent-branches... (post written April 1st but not a joke) and quite enjoying it. Shows me the last 10 branches I worked on (very easy to edit the alias definition to get more or fewer than 10), sorted by date, most recent first. It's been handy in all sorts of situations, especially because one of our internal libraries needs a bugfix or a new feature every 3 months or so. So every time I cd into that repo, I have no clue what I did last, but `git lb` tells me right away.
ComputerGuru yesterday at 8:42 PM
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!
tyre today at 3:27 AM
I made a lovely little TUI for this, with Charm (https://charm.sh)
https://github.com/tyre/recent-branches
Enjoy!
metmac yesterday at 9:00 PM
Huge fan of `git recent` [0] for this purpose.
dalton74 today at 12:07 AM
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.
Trace88 yesterday at 11:52 PM
Such a small quality of life improvement. My `git branch` output is a graveyard sometimes, this would be handy.
m4rtink today at 1:17 AM
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
tomtom1337 yesterday at 8:58 PM
I love this little fzf bash function that I wrote a few years ago: https://gist.github.com/thomasaarholt/141df779f3f16b641701b4...
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.
deleted today at 12:29 AM
cryptolobster today at 1:09 AM
TIL Git can do this without a shell script. Iβve been manually sorting through branches like an idiot
zahlman yesterday at 8:48 PM
How many branches would you need to have to make this worthwhile?
rglover today at 1:12 AM
Nice. Will help solve some mysteries on older projects.
thr0waway001 today at 1:46 AM
nice. I made myself pretty much the same command couple years ago but called it 'latestbranches'.
mcdow yesterday at 11:02 PM
yep, i have a little helper in my zshrc for this sort of thing:
alias git-hot-refs="git branch --sort=committerdate | tail"
bewareofscams yesterday at 8:01 PM
Or just have `jj log` custom-configured.
woodruffw yesterday at 9:07 PM
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.)tikhonj today at 12:36 AM
Let's sort git branches by quality, better branches towards the top, slop at the bottom.
jeffbee yesterday at 11:04 PM
Feels like the type of problem you could simply choose to not have in the first place (by not using git).
monster_truck yesterday at 8:54 PM
I just click on tower and open it, much better
matltc today at 1:03 AM
Amazing what one can learn from rtfm