Last active
September 9, 2026 00:12
-
-
Save thadeu/d414608edc670e8da3d60f68242c1a3c to your computer and use it in GitHub Desktop.
git tg
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| git config --global alias.tg '!f() { bump="patch"; while [ $# -gt 0 ]; do case "$1" in --major) bump="major"; shift ;; --minor) bump="minor"; shift ;; --patch) bump="patch"; shift ;; *) shift ;; esac; done; last=$(git tag --sort=v:refname | tail -n 1); if [ -z "$last" ]; then case "$bump" in major) new="v1.0.0" ;; minor) new="v0.1.0" ;; patch) new="v0.0.1" ;; esac; else case "$last" in v*) prefix="v"; version=${last#v} ;; *) prefix=""; version=$last ;; esac; major=$(echo "$version" | cut -d. -f1); minor=$(echo "$version" | cut -d. -f2); patch=$(echo "$version" | cut -d. -f3); [ -z "$minor" ] && minor=0; [ -z "$patch" ] && patch=0; case "$bump" in major) major=$((major + 1)); minor=0; patch=0 ;; minor) minor=$((minor + 1)); patch=0 ;; patch) patch=$((patch + 1)) ;; esac; new="${prefix}${major}.${minor}.${patch}"; fi; git tag "$new" && echo "$new"; }; f' |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage git tg