• Hacker News
  • new|
  • comments|
  • show|
  • ask|
  • jobs|
  • cryptolobster 4 hours

    TIL Git can do this without a shell script. I’ve been manually sorting through branches like an idiot

  • tyre 1 hours

    I made a lovely little TUI for this, with Charm (https://charm.sh)

    https://github.com/tyre/recent-branches

    Enjoy!

  • tomtom1337 8 hours

    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.

  • ComputerGuru 8 hours

    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!

  • jbranchaud 4 hours

    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...

  • thr0waway001 3 hours

    nice. I made myself pretty much the same command couple years ago but called it 'latestbranches'.

  • dalton74 5 hours

    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.

  • bewareofscams 9 hours

    Or just have `jj log` custom-configured.

  • Trace88 5 hours

    Such a small quality of life improvement. My `git branch` output is a graveyard sometimes, this would be handy.

  • tikhonj 4 hours

    Let's sort git branches by quality, better branches towards the top, slop at the bottom.

  • 4 hours

  • rglover 3 hours

    Nice. Will help solve some mysteries on older projects.

  • rmunn 2 hours

    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.

  • woodruffw 8 hours

    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.)

  • mcdow 6 hours

    yep, i have a little helper in my zshrc for this sort of thing:

    alias git-hot-refs="git branch --sort=committerdate | tail"

  • monster_truck 8 hours

    I just click on tower and open it, much better

  • jeffbee 6 hours

    Feels like the type of problem you could simply choose to not have in the first place (by not using git).

  • matltc 4 hours

    Amazing what one can learn from rtfm

  • metmac 8 hours

    Huge fan of `git recent` [0] for this purpose.

    [0] - https://github.com/paulirish/git-recent

    metmac 8 hours

    Spoiler it’s fzf under the hood. But it’s perfect and simple.

  • zahlman 8 hours

    How many branches would you need to have to make this worthwhile?

    jamietanna 8 hours

    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

    woodruffw 8 hours

    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.

    spike021 6 hours

    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.

  • m4rtink 3 hours

    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

    fwip 3 hours

    > Just configure git branch to sort by the last commit date:

    > git config branch.sort committerdate

    > You can also supply this on a one-off basis as git branch --sort committerdate.

    These don't seem like hacks to me. What do you have in mind?

    dataflow 3 hours

    Probably because most of the time you list branches you goal isn't to discover what exists, but to find the specific one you're looking for.

  • asb 9 hours

    Even better (IMHO!) is `git config branch.sort -committerdate` (note the `-`). This will sort newest committer date first.

    mmsc 7 hours

    `git config --global branch.sort -committerdate`

    hsuduebc2 3 hours

    Thanks!

    pkaodev 9 hours

    I have this as an alias in my .zshrc!! Very handy

    johnwheeler 4 hours

    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 3 hours

    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.

    nulltrace 6 hours

    Rebase an old branch and it suddenly looks recent again. The rewritten tip gets a fresh committer date.

    seattle_spring 3 hours

    I would hope so

    quuxplusone 5 hours

    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.