Skip to content

Instantly share code, notes, and snippets.

@the-glima
Forked from rponte/get-latest-tag-on-git.sh
Last active May 28, 2020 08:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save the-glima/5b5503c60df6371c22d611a0c87c2821 to your computer and use it in GitHub Desktop.
Save the-glima/5b5503c60df6371c22d611a0c87c2821 to your computer and use it in GitHub Desktop.
[Git] Getting the latest tag #website
# 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.
git describe
# With --abbrev set to 0, the command can be used to find the closest tagname without any suffix:
git describe --abbrev=0
# other examples
git describe --abbrev=0 --tags # gets tag from current branch
git describe --tags `git rev-list --tags --max-count=1` # gets tags across all branches, not just the current branch
@the-glima
Copy link
Author

the-glima commented Apr 9, 2020

From latest to oldest:

$ git ls-remote --tags --sort=committerdate | grep -o 'v.*' | sort -r

v1.2.3
v1.2.2
v1.2.1
v1.2.0
v1.1.0

Or, what I wanted, just the single latest one:

 $ git ls-remote --tags --sort=committerdate | grep -o 'v.*' | sort -r | head -1

v1.2.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment