Skip to content

Instantly share code, notes, and snippets.

@hoangbkit
Forked from rponte/get-latest-tag-on-git.sh
Last active July 31, 2018 04:31
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 hoangbkit/2d4357b4dc7d89dff3a087ee8c72ffd9 to your computer and use it in GitHub Desktop.
Save hoangbkit/2d4357b4dc7d89dff3a087ee8c72ffd9 to your computer and use it in GitHub Desktop.
Getting latest tag on git repository
# 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
# To delete remote tags (before deleting local tags) simply do:
git tag -l | xargs -n 1 git push --delete origin
# and then delete the local copies:
git tag | xargs git tag -d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment