show all tags excluding release candidates with git ls-remote

Viewed 233

I currently have a deployment process where production release tags are in the form v1.0.1 and stage/ release candidates follow the form v1.0.1-rc.1. I see that I can use the below to pull in only release candidates:

git ls-remote --tags --refs --sort tag origin "refs/tags/v*.*.*-rc.*"

ba2ed... refs/tags/v1.0.1-rc.1
f37ac... refs/tags/v1.0.1-rc.2

But how can I do the opposite where I only see tags like v1.0.1, v1.0.2, etc where I might exclude tags containing the -rc. pattern?

1 Answers

Use grep -v to exclude (filter out) lines of output:

git ls-remote --tags --refs --sort tag origin "refs/tags/v*" | grep -v -e "-rc\.[0-9]\+$"

The regular expression -rc\.[0-9]\+$ means:

-rc — literally
\. — literal dot
[0-9]\+ — any number of digits
$ — end of the string to avoid matching "-rc.1" in the middle
Related