brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: sort your branches by last commit with branch.sort

Git settings and fixes
~/tips/tip-git-branch-sort-committerdate

git branch --sort=-committerdate

Lists your branches with the most recently committed one at the top.

By default git branch lists branches alphabetically. That is rarely the order I care about.

git branch --sort=-committerdate

This puts the branch with the newest commit on top. The minus sign means descending. The sort keys are the same ones git for-each-ref uses, so committerdate is one of many.

You do not have to type it every time. There is a config variable for the default order, which the docs call branch.sort:

git config --global branch.sort -committerdate

From then on, plain git branch lists the branches you touched most recently first. With a few dozen branches, the one you want is on the first screen and the dead ones sink to the bottom.

Add -vv for a bit more. It shows the commit and subject per branch and its upstream branch.

The caveat: committer date is the date of the last commit on that branch. It says nothing about when you last switched to it, so a branch you looked at yesterday but did not commit on can still sit low in the list. Also, an explicit --sort on the command line overrides the setting.

Further reading: git branch documentation, On this site: fetch.prune cleans up branches that no longer exist remotely, On this site: git switch – takes you back to the branch you were on

Going deeper: Guide: advanced tmux, a config that grows with you, formats, layouts and more

More Git settings and fixes tips git merge --abort concurrency: git rev-parse --show-toplevel git config --get-regexp '^user\.' git commit -C ORIG_HEAD All Git settings and fixes tips (40) All topics

Link