Skip to content

Instantly share code, notes, and snippets.

@sumanmaity112
Last active November 15, 2022 19:22
Show Gist options
  • Save sumanmaity112/600ce8bffe1e504857ca37ba4acc4f24 to your computer and use it in GitHub Desktop.
Save sumanmaity112/600ce8bffe1e504857ca37ba4acc4f24 to your computer and use it in GitHub Desktop.
Get latest tag (sort by semver/refname) on git repository filtered by optional prefix
#!/usr/bin/env bash
set -euo pipefail
# git version 2.38.1
_get_latest_tag(){
local prefix="${1:-}"
git tag -i -l "${prefix}*" --sort -v:refname | head -n1
}
_get_latest_tag "$@"
# ./get-latest-tag-on-git.sh "v"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment