Live data from Hacker News

Sort branches by last commit date

ryangreenberg.com

41–50 of 56 posts

Re: Sort branches by last commit date

#41
post #29

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

Git defaults are a bit weird. You also have to enable rerere yourself, when it should be on by default.

Re: Sort branches by last commit date

#42
post #6

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

I often have a few dozen branches open at work, because I'm often waiting for reviews to go through but don't want to be blocked. I also often run little experiments in the background, like having an AI agent try to reliably reproduce a flake I saw in the CI (and then producing a fix for the reliably reproducer).

Re: Sort branches by last commit date

#44
post #37

I made a lovely little TUI for this, with Charm ( https://charm.sh ) https://github.com/tyre/recent-branches Enjoy!

Here is a much, much, much lighter weight version I've been using since forever:

    gi() {
        git branch --sort=-committerdate |\
         grep -v '^\*' | cut -d' ' -f3 | fzf |\
         xargs git checkout
    }
fzf handles the TUI part

Re: Sort branches by last commit date

#46

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!

Every day, I learn a cool new thing that fish can do

Re: Sort branches by last commit date

#49
post #2

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

.gitconfig:

  ```
  [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

#50
post #2

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

What makes knowledge "specialized" to you? Most devs use git.

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.

Post reply on HN