Reputation: 761
I have several releases with different tag names (e.g v1.0, v1.0.5 and v2.4 etc). I only publish a release when my project is at a stable condition.
On a separate machine, I want to pull the latest version that is 'stable', that is to say, the latest release that has been made.
Is there a way to achieve this through Git?
Upvotes: 0
Views: 839
Reputation: 7727
If your tags are named consistently with version numbers as your example that v1.0
< v1.0.5
< v2.4
, you can just get the last line from git tag
as the latest.
So the command should be as follows, assuming the remote reference name is origin
git fetch --tags origin
git checkout $(git tag | tail -1)
To make it one line command.
git fetch --tags origin && git checkout $(git tag | tail -1)
Upvotes: 1
Reputation: 14843
Make sure you are using tag objects (git tag -m
), then git fetch
to sync the repos, then do git for-each-ref --sort=taggerdate --format '%(refname:short)' refs/tags | tail -1
to get the most recent tag and check that out.
Upvotes: 1