22 comments

  • jbranchaud3 hours 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. <a href="https:&#x2F;&#x2F;github.com&#x2F;jbranchaud&#x2F;dotfiles&#x2F;blob&#x2F;main&#x2F;zshrc.local#L38" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;jbranchaud&#x2F;dotfiles&#x2F;blob&#x2F;main&#x2F;zshrc.local...</a>
  • rmunn1 hour ago
    I have been using the `git lb` alias suggested by <a href="https:&#x2F;&#x2F;ses4j.github.io&#x2F;2020&#x2F;04&#x2F;01&#x2F;git-alias-recent-branches&#x2F;" rel="nofollow">https:&#x2F;&#x2F;ses4j.github.io&#x2F;2020&#x2F;04&#x2F;01&#x2F;git-alias-recent-branches...</a> (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&#x27;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.
  • asb8 hours ago
    Even better (IMHO!) is `git config branch.sort -committerdate` (note the `-`). This will sort newest committer date first.
    • mmsc5 hours ago
      `git config --global branch.sort -committerdate`
    • nulltrace5 hours ago
      Rebase an old branch and it suddenly looks recent again. The rewritten tip gets a fresh committer date.
      • quuxplusone4 hours ago
        Yes. This is what one wants, since if you have recently rebased it, you&#x27;re clearly doing work with it. Meanwhile, branches you don&#x27;t care to touch sink to the bottom of the list.
      • seattle_spring2 hours ago
        I would hope so
    • pkaodev8 hours ago
      I have this as an alias in my .zshrc!! Very handy
    • johnwheeler3 hours ago
      Even better, &quot;hey, chat GPT, list my branches by commit date.&quot;<p>I know that&#x27;s not a popular answer, but I&#x27;m just trying to demonstrate the reality that this kind of knowledge isn&#x27;t specialized anymore.
      • hsuduebc22 hours ago
        Heh. &quot;Just Google it&quot; answers we&#x27;re never particular conversation lubricant as they are not now. But of course you are right we live in age of wonder once again.
  • tyre37 minutes ago
    I made a lovely little TUI for this, with Charm (<a href="https:&#x2F;&#x2F;charm.sh" rel="nofollow">https:&#x2F;&#x2F;charm.sh</a>)<p><a href="https:&#x2F;&#x2F;github.com&#x2F;tyre&#x2F;recent-branches" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;tyre&#x2F;recent-branches</a><p>Enjoy!
  • ComputerGuru7 hours ago
    FYI&#x2F;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!
  • metmac7 hours ago
    Huge fan of `git recent` [0] for this purpose.<p>[0] - <a href="https:&#x2F;&#x2F;github.com&#x2F;paulirish&#x2F;git-recent" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;paulirish&#x2F;git-recent</a>
    • metmac7 hours ago
      Spoiler it’s fzf under the hood. But it’s perfect and simple.
  • dalton743 hours ago
    Our team&#x27;s `git branch` output is a graveyard. Sorting by last commit would be a godsend for quickly identifying active work and stale branches.
  • Trace884 hours ago
    Such a small quality of life improvement. My `git branch` output is a graveyard sometimes, this would be handy.
  • m4rtink2 hours 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&#x2F;alias hack. :P
    • dataflow2 hours ago
      Probably because most of the time you list branches you goal isn&#x27;t to discover what exists, but to find the specific one you&#x27;re looking for.
    • fwip2 hours ago
      &gt; Just configure git branch to sort by the last commit date:<p>&gt; git config branch.sort committerdate<p>&gt; You can also supply this on a one-off basis as git branch --sort committerdate.<p>These don&#x27;t seem like hacks to me. What do you have in mind?
  • tomtom13377 hours ago
    I love this little fzf bash function that I wrote a few years ago: <a href="https:&#x2F;&#x2F;gist.github.com&#x2F;thomasaarholt&#x2F;141df779f3f16b641701b4782431f7c3" rel="nofollow">https:&#x2F;&#x2F;gist.github.com&#x2F;thomasaarholt&#x2F;141df779f3f16b641701b4...</a><p>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.
  • cryptolobster2 hours ago
    TIL Git can do this without a shell script. I’ve been manually sorting through branches like an idiot
  • rglover2 hours ago
    Nice. Will help solve some mysteries on older projects.
  • thr0waway0012 hours ago
    nice. I made myself pretty much the same command couple years ago but called it &#x27;latestbranches&#x27;.
  • zahlman7 hours ago
    How many branches would you need to have to make this worthwhile?
    • jamietanna7 hours ago
      At any time I&#x27;m working across 5-30 branches (some when I&#x27;m reviewing other folks&#x27; code) so it&#x27;s handy to see my latest branches
    • spike0215 hours ago
      At my current job it&#x27;s fairly frequent that I have 5+ active branches open for a repo. Not ideal and that&#x27;s another topic, but it is nice to be able to sort branches because of that.
    • woodruffw7 hours ago
      I&#x27;ve seen monorepos with over 10k active branches. But even at a smaller scale (10-100 branches), it becomes useful when manually stacking and&#x2F;or rebasing, especially if you have a smaller terminal.
  • mcdow5 hours ago
    yep, i have a little helper in my zshrc for this sort of thing:<p>alias git-hot-refs=&quot;git branch --sort=committerdate | tail&quot;
  • bewareofscams8 hours ago
    Or just have `jj log` custom-configured.
  • tikhonj3 hours ago
    Let&#x27;s sort git branches by quality, better branches towards the top, slop at the bottom.
  • woodruffw6 hours ago
    Another useful one if you have a large number of tags and want to see the most recently created ones first:<p><pre><code> git config --global tag.sort -creatordate </code></pre> (`-creatordate` reverses the sort so that the newest come first.)
  • monster_truck7 hours ago
    I just click on tower and open it, much better
  • jeffbee5 hours ago
    Feels like the type of problem you could simply choose to not have in the first place (by not using git).
  • matltc3 hours ago
    Amazing what one can learn from rtfm