Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get latest tag name? [duplicate]

Tags:

How to get latest tag name (like version) of current branch?

like image 751
VeroLom Avatar asked Nov 25 '10 13:11

VeroLom


People also ask

How do I get the latest tag?

JB. JB. Returns the latest tag in the current branch. To get the latest annotated tag which targets only the current commit in the current branch, use git describe --exact-match --abbrev=0 .

How do I checkout the latest tag in git?

In order to checkout a Git tag, use the “git checkout” command and specify the tagname as well as the branch to be checked out. Note that you will have to make sure that you have the latest tag list from your remote repository.

How do I see git tags?

Find Latest Git Tag Available In order to find the latest Git tag available on your repository, you have to use the “git describe” command with the “–tags” option. This way, you will be presented with the tag that is associated with the latest commit of your current checked out branch.


1 Answers

git describe should be enough

The command finds the most recent tag that is reachable from a commit.
If the tag points to the commit, then only the tag is shown.
Otherwise, it suffixes the tag name with the number of additional commits on top of the tagged object and the abbreviated object name of the most recent commit.

With --abbrev set to 0, the command can be used to find the closest tagname without any suffix:

[torvalds@g5 git]$ git describe --abbrev=0 v1.0.5^2 tags/v1.0.0 

For tags matching a certain pattern:

git describe --tags --abbrev=0 --match release-* 

(Peterino's comment)

For the latest tag on all the branches (not just the latest branch)

git describe --tags $(git rev-list --tags --max-count=1) 

(from kilianc's answer)

like image 57
VonC Avatar answered Oct 01 '22 22:10

VonC