Skip to content

Instantly share code, notes, and snippets.

@thadeu
Created June 12, 2026 20:43
Show Gist options
  • Select an option

  • Save thadeu/d414608edc670e8da3d60f68242c1a3c to your computer and use it in GitHub Desktop.

Select an option

Save thadeu/d414608edc670e8da3d60f68242c1a3c to your computer and use it in GitHub Desktop.
git tg
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'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment