git-tag
git-tag
Create a new git tag whose name is the next semver version after the latest existing tag.
When to use
- When the user asks to create a release tag, version tag, or git tag
- When the user wants to bump the major / minor / patch version
- When the user runs
/git-tag
Argument
The argument selects which component to increment. Only major, minor, or patch are accepted. If the argument is omitted, default to patch. Anything else must be rejected with a clear error message — never silently fall back.
Instructions
-
Verify the working tree is on the default branch. This is a hard requirement: tags published from feature branches confuse downstream consumers, so abort early if it is not satisfied.
- Determine the default branch with
git symbolic-ref refs/remotes/origin/HEAD(typically resolves toorigin/mainororigin/master). Iforigin/HEADis not set, fall back togit remote show originand parse theHEAD branchline. - Compare against
git rev-parse --abbrev-ref HEAD. If they differ, stop and tell the user which branch they are on and which one they need to switch to. Do not switch branches automatically — the user may have uncommitted work.
- Determine the default branch with
-
Make sure the working tree is clean and up to date.
- Run
git status --porcelain. If it returns any output, abort and ask the user to commit or stash first. Tagging on top of a dirty tree creates a tag that does not match what gets pushed. - Run
git fetch --tags originso the latest-tag lookup sees tags created by other contributors.
- Run
-
Find the latest semver tag.
- Use
git for-each-ref --sort=-v:refname --format='%(refname:short)' 'refs/tags/v*' 'refs/tags/[0-9]*'to list tags sorted by version order.-v:refnameis git's built-in semver-aware sort, which handlesv1.10.0 > v1.9.0correctly (lexicographic sort would get this wrong). - Take the first entry that matches strict semver:
^v?(\d+)\.(\d+)\.(\d+)$. Pre-release / build-metadata tags (e.g.v1.2.3-rc.1,v1.2.3+build.4) are skipped for bump base selection — bumping from a pre-release is ambiguous, so we anchor to the last stable release. - If no semver tag exists, treat the previous version as
v0.0.0so apatchbump producesv0.0.1,minorproducesv0.1.0, andmajorproducesv1.0.0. Tell the user this is the first tag.
- Use
-
Compute the next version. Apply the standard semver bump rules — when a higher component increments, the lower components reset to zero.
major:X.Y.Z→(X+1).0.0minor:X.Y.Z→X.(Y+1).0patch:X.Y.Z→X.Y.(Z+1)- Preserve the
vprefix style of the latest tag. If the latest tag isv1.2.3, the new tag isvX.Y.Z; if it is1.2.3, the new tag isX.Y.Z. When there is no prior tag, default to thev-prefixed form because it is the more common convention.
-
Confirm with the user before creating the tag. Show: the current branch, the latest tag, the bump type, and the new tag name. Wait for confirmation. This is the last reversible point — once a tag is pushed it is hard to retract cleanly, so a single confirmation prompt here is worth the friction.
-
Create an annotated, signed tag.
- Run
git tag -s -a <new-tag> -m "Release <new-tag>".-amakes it an annotated tag (carries author + date + message, which is what release tooling expects), and-sGPG-signs it so consumers can verify provenance. - If signing fails because the user has no GPG key configured, report the error verbatim and stop. Do not silently fall back to an unsigned tag — the user explicitly opted into signed releases by using this skill, and a downgrade would be surprising.
- Run
-
Do not push automatically. Print the exact command the user can run to publish it (
git push origin <new-tag>) and let them decide. Pushing is irreversible-ish (other clones will fetch it within seconds) and should be an explicit human decision.
Important notes
git pushis intentionally not inallowed-tools. The user runs the push themselves so they get one final chance to review.- Strict semver only: reject pre-release suffixes (
-rc.1,-beta) and build metadata (+sha.abc) in the input validation. They are fine to exist as tags in the repo (we just skip past them when finding the bump base), but this skill does not produce them — keeping the surface small avoids the hairy edge cases around pre-release ordering. - The "default branch" check uses the remote's HEAD, not a hardcoded
main. Some repos still usemaster, some usedevelop, and a few use something custom. Reading fromorigin/HEADkeeps this skill portable. - Never delete or move existing tags. If the computed tag already exists (e.g. someone else tagged concurrently between
fetchandtag), abort and report it — silently re-pointing a tag would rewrite release history.
More from guni1192/agent-skills
create-pr
Create a pull request by branching from the default branch, committing changes with a signed commit, and pushing.
8pasta
Perform PASTA (Process for Attack Simulation and Threat Analysis) threat modeling by guiding through 7 stages interactively.
7docker-init
Initialize Dockerfile and .dockerignore for the current project by detecting language, framework, and package manager.
7designdoc
Write a design document following Google's design doc practices. Guides through structured sections interactively to produce a comprehensive design doc.
5