Skip to content

Instantly share code, notes, and snippets.

@damiankloip
Last active May 22, 2018 10:38
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 damiankloip/a6b2f04670f23c424c288112d8761637 to your computer and use it in GitHub Desktop.
Save damiankloip/a6b2f04670f23c424c288112d8761637 to your computer and use it in GitHub Desktop.
git next-tag script
#!/bin/sh
if ! [ -x "$(command -v semver)" ]; then
echo 'Error: semver is not installed. Install using `npm install --global --save semver`' >&2
exit 1
fi
# Get tags ordered correctly, and take the last one.
last="$(git tag --sort=v:refname | tail -n1)"
if [ -z "$last" ]; then
echo "No last tag found"
exit 0
fi
# $1 can be major, minor, or patch. Defaults to patch.
next=$(semver -i "${1-patch}" "$last")
echo "Last tag: $last"
echo "Next tag: $next"
@damiankloip
Copy link
Author

damiankloip commented May 22, 2018

If this script is executable and included in your PATH, you will be able to run this like git next-tag.

The version increment defaults to 'patch', but can pass 'major', 'minor', or 'patch', for example: git next-tag minor

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