138 pointsby speckx7 days ago29 comments
  • asb2 days ago
    Even better (IMHO!) is `git config branch.sort -committerdate` (note the `-`). This will sort newest committer date first.
    • mmsc2 days ago
      `git config --global branch.sort -committerdate`
    • nulltrace2 days ago
      Rebase an old branch and it suddenly looks recent again. The rewritten tip gets a fresh committer date.
      • quuxplusone2 days 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.
      • mmsca day ago
        .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
          ```
      • seattle_spring2 days ago
        I would hope so
    • pkaodev2 days ago
      I have this as an alias in my .zshrc!! Very handy
    • johnwheeler2 days 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.

      • hsuduebc22 days 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.
      • sublineara day ago
        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.

        • johnwheeler18 hours ago
          It's not worse than the man. It's better. You're just trying to protect your ego. It's ridiculous.
          • sublinear12 hours ago
            I'm fairly certain that at least half of the people commenting (and all of the people who downvoted you) have over a decade of git muscle memory in their fingers. That's far faster than asking AI, and sometimes probably even faster than their terminal can print.

            I promise you nobody is trying to show off. Git's CLI is notoriously inconsistent and verbose, and every GUI for it is always missing a ton of relevant features because it was designed for someone else's itch.

            Now we have people like you trying to wedge AI into the discussion. I'm sorry dude. There's nothing to argue here. Git is the most important tool we have as developers. It's worth learning because the whole point is precise changes. We put up with the bad interfaces because it's otherwise just that good.

      • wakawaka2813 hours ago
        It's still specialized, but looking it up has gotten easier. It's better to use the right tool for the job. What's next, are you gonna tell ChatGPT to list your files too?
  • ComputerGuru2 days 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!
    • yonatan8070a day ago
      Every day, I learn a cool new thing that fish can do
  • jbranchaud2 days ago
    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...
  • metmac2 days ago
    Huge fan of `git recent` [0] for this purpose.

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

    • metmac2 days ago
      Spoiler it’s fzf under the hood. But it’s perfect and simple.
  • rmunn2 days ago
    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.
  • dalton742 days 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.
    • erua day ago
      When I'm working on a repository where the remote is shared (like a corporate GitHub repository where not everyone has their own GitHub fork) I tend to name all my branches like 'eru/<something>'. That way I can quickly find my work, and I can also confidently delete branches without worrying about stepping on other people's toes nor being stepped on by accident. I encourage co-workers to do the same, but haven't strictly required it from team members.
  • krautsauera day ago
    There's a bunch of these good ideas here: https://news.ycombinator.com/item?id=43169435
  • amarshalla day ago
    I rarely care about the date of the commit on the branch to determine recency, I care about when I last switched to the branch.

    This comment gets it correct https://news.ycombinator.com/item?id=49504860

    I wrote my own version to do this nearly 10 years ago: https://github.com/amarshall/git-recent-branches

  • m4rtink2 days ago
    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
    • dataflow2 days ago
      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.
    • erua day ago
      Git defaults are a bit weird. You also have to enable rerere yourself, when it should be on by default.
    • fwip2 days ago
      > 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?

  • tomtom13372 days ago
    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.

  • qznca day ago
    I wonder about the "modern" git part. Here is how to do it in 2013: https://stackoverflow.com/a/10693888/2361979
  • tyrea day ago
    I made a lovely little TUI for this, with Charm (https://charm.sh)

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

    Enjoy!

    • petesergeanta day ago
      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
  • chis21 hours ago
    Sometimes I’m amazed anyone is willing to live without a git ui. The graph structure git uses is just such a natural fit for visual processing, plus the default git ux is borderline user-hostile until you master it.

    What’s also funny is that early in my career I could tell other engineers looked down on me for using a git UI, perhaps assuming I was too stupid to use the terminal. I suspect that this mindset propagates git use to the next generation.

    • wakawaka2813 hours ago
      Well, it's a fit for visual processing only in simple cases. If your graph looks like spaghetti, you need other ways to think about it. If the `git log --oneline --graph` view (or whatever options trigger it) is not good enough, then a full-blown GUI won't do it for me either.
  • zeroqa day ago
    I have to make a confession. I've been using different version control system for the last 25 years, but everytime I'm doing anything more complicated than basic commit/push I feel absolutely overwhelmed and terrified that I'm about to break something.
  • zahlman2 days ago
    How many branches would you need to have to make this worthwhile?
    • jamietanna2 days 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
    • woodruffw2 days 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.
    • spike0212 days 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.
      • erua day ago
        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).
  • simonsayssoa day ago
    When I get worried about my skill set or career going away from LLMs, I get hit with a post like this with huge traction describing something I’ve already found and solved for myself. It makes me realize: I’m probably ok for a while because of all these experiences and knowledge, and I’m quite shit at communicating something that’s obviously valuable to others.

    This was one of the better usability changes I made to git, yes you should probably set it for yourself

  • 2 days ago
    undefined
  • Trace882 days ago
    Such a small quality of life improvement. My `git branch` output is a graveyard sometimes, this would be handy.
  • cryptolobster2 days ago
    TIL Git can do this without a shell script. I’ve been manually sorting through branches like an idiot
  • rglover2 days ago
    Nice. Will help solve some mysteries on older projects.
  • thr0waway0012 days ago
    nice. I made myself pretty much the same command couple years ago but called it 'latestbranches'.
  • mcdow2 days ago
    yep, i have a little helper in my zshrc for this sort of thing:

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

  • woodruffw2 days 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.)
  • tikhonj2 days ago
    Let's sort git branches by quality, better branches towards the top, slop at the bottom.
  • i18nera day ago
    [dead]
  • bewareofscams2 days ago
    Or just have `jj log` custom-configured.
    • surajrmala day ago
      It is sorted this way by default.
  • jeffbee2 days ago
    Feels like the type of problem you could simply choose to not have in the first place (by not using git).
  • matltc2 days ago
    Amazing what one can learn from rtfm
  • monster_truck2 days ago
    I just click on tower and open it, much better