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: tag.sort version:refname puts git tags in version order

Git
~/tips/tip-git-tag-sort-version

git config --global tag.sort version:refname

Sorts tags as versions, so v1.10 comes after v1.9 instead of before it.

By default git tag sorts alphabetically, which puts v1.10 before v1.9. That’s wrong for anyone reading it as version numbers.

git config --global tag.sort version:refname

Now git tag treats the tag names as versions and sorts v1.9 before v1.10. For a single command, there’s the option form, and a minus sign reverses the order so the newest comes first:

git tag --sort=-v:refname | head -5

v:refname is a short way to write version:refname. I like the reversed form for scripts that need the latest release tag.

Pre-releases can look odd. By default v2.0-rc1 sorts after v2.0, because it’s a longer string. The setting versionsort.suffix fixes that: git config --global versionsort.suffix -rc tells git that tags ending in -rc something come before the plain version.

The sort only looks at names. A tag called release-2026 next to v1.4 sorts by the text, not by date. If your tags aren’t consistent, --sort=-creatordate sorts by when they were made, which is often what you actually want to know.

Further reading: git-tag documentation, git-config documentation

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

More Git tips git show-branch main feature git log --stat -5 git merge --no-ff feature -m "Merge feature" git merge --squash feature git merge --abort All Git tips (144) All topics

Link