When I enter a command:
git tag -l
I get such results:
rc-0.9.0.0
rc-0.9.0.1
rc-0.9.0.10
rc-0.9.0.11
rc-0.9.0.12
rc-0.9.0.2
Combining the answers already here:
git -c 'versionsort.suffix=-' tag --list --sort=-v:refname
suffix=-
will prevent 2.0-rc
coming "after" 2.0
--sort=-
will put the highest version number at the top.git -c 'versionsort.suffix=-' ls-remote -t --exit-code --refs --sort=-v:refname "$repo_url" \
| sed -E 's/^[[:xdigit:]]+[[:space:]]+refs\/tags\/(.+)/\1/g'
The advantage of this is that no objects are downloaded from the remote.
For more info see this answer.