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
Sort branches by last commit date
41–50 of 56 posts
Re: Sort branches by last commit date
#42How many branches would you need to have to make this worthwhile?
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.
Re: Sort branches by last commit date
#43Re: Sort branches by last commit date
#44I made a lovely little TUI for this, with Charm ( https://charm.sh ) https://github.com/tyre/recent-branches Enjoy!
gi() {
git branch --sort=-committerdate |\
grep -v '^\*' | cut -d' ' -f3 | fzf |\
xargs git checkout
}
fzf handles the TUI partRe: Sort branches by last commit date
#45Re: Sort branches by last commit date
#46FYI/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!
Re: Sort branches by last commit date
#47Re: Sort branches by last commit date
#48Or just have `jj log` custom-configured.
Re: Sort branches by last commit date
#49Even better (IMHO!) is `git config branch.sort -committerdate` (note the `-`). This will sort newest committer date first.
Rebase an old branch and it suddenly looks recent again. The rewritten tip gets a fresh committer date.
```
[rebase]
instructionFormat = %s%nexec GIT_COMMITTER_DATE=\"%cI\" GIT_COMMITTER_NAME=\"%cN\" GIT_COMMITTER_EMAIL=\"%cE\" git commit --amend --no-edit%n
committerDateIsAuthorDate = true
```Re: Sort branches by last commit date
#50Even better (IMHO!) is `git config branch.sort -committerdate` (note the `-`). This will sort newest committer date first.
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.
Even better than ChatGPT is just doing the thing on reflex. Not every manual step is necessarily a tedious chore nor even slower when you actually know what you're doing.
I'm not saying this out of hubris, but there's no man vs machine story here when the machine needs babysitting and is still worse at everything. Nobody is resisting AI at this point. We just need to get shit done and that always requires knowing something. Every new technology quickly hits a ceiling and finds its niche. This isn't it.