Skip to content
HN On Hacker News ↗

Sort branches by last commit date

▲ 139 points 53 comments by speckx 2w ago HN discussion ↗

Pangram verdict · v3.3

We believe that this entire text is human-written.

0 %

AI likelihood · overall

Human
100% human-written 0% AI-generated
SEGMENTS · HUMAN 1 of 1
SEGMENTS · AI 0 of 1
WORD COUNT 222
PEAK AI % 0% · §1
Analyzed
Aug 30
backend: pangram/v3.3
Segments scanned
1 windows
avg 222 words each
Distribution
100 / 0%
human / AI fraction
Verdict
Human
Pangram v3.3

Article text · 222 words · 1 segments analyzed

Human AI-generated
§1 Human · 0%

August 24, 20269:55 AMI have too many git branches and like many people I developed a convoluted script to show me the most recent ones. I ran this command many times a day for years: function branches { for k in `git branch | sed "s/^..//"`; do echo -e `git log --color -1 --pretty=format:"%Cgreen%ci %Cblue%cr%Creset" "$k"`\\t"$k"; done | sort } This outputs the date as the first column in the output so that sort works. Turns out with modern git it’s totally unnecessary. 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. What else can you sort by? The manual says “The keys supported are the same as those in git-for-each-ref(1).” The manpage for git-for-each-ref lists a ton of fields, including some that don’t make sense to me as sort keys. Here are a few that stood out as interesting: authordate, committerdate, creatordate, taggerdate contents:size: The size in bytes of the commit or tag message. push: The name of a local ref which represents the @{push} location for the displayed ref. refname: The name of the ref (the part after $GIT_DIR/) (this is the default). upstream: The name of a local ref which can be considered “upstream” from the displayed ref. Git