LinuxCommandLibrary

git-rename-tag

Rename an existing Git tag

TLDR

Rename an existing Git tag locally and remotely

$ git rename-tag [old_tag_name] [new_tag_name]
copy

SYNOPSIS

git-rename-tag [-f] [-r remote] old-tag new-tag

PARAMETERS

-f, --force
    Force creation of new tag if it already exists.

-r remote, --remote remote
    Remote repo to delete old and push new tag (e.g., origin).

DESCRIPTION

Git tags serve as immutable markers for specific commits, but core Git lacks a direct rename feature to preserve history integrity. git-rename-tag is a third-party Bash or Perl script that automates renaming by capturing the old tag's commit hash, deleting the old tag, creating a new tag on the same commit, and optionally updating a remote repository by pushing the deletion and new tag.

This utility simplifies a multi-step process that would otherwise require manual git tag -d, git tag new old-commit, git push --delete, and git push commands. It supports both lightweight and annotated tags, preserving annotations if present. Ideal for fixing typos in version tags like v1.0 to v1.0.1 before wide dissemination.

Caveat: Renaming shared remote tags rewrites references, requiring collaborators to prune stale tags via git fetch --prune or git tag -d old-tag. Always coordinate team-wide to avoid confusion. Scripts vary slightly by implementation but follow this pattern.

CAVEATS

Not a core Git command; install script separately.
Rewrites shared tag history—notify collaborators.
Remote must be pushable; fails if protected.

EXAMPLE

git-rename-tag -r origin v1.0 v1.0.1
Deletes v1.0 locally/remote, creates v1.0.1 on same commit, pushes to origin.

INSTALLATION

curl -O https://raw.githubusercontent.com/mvinkus/git-rename-tag/master/git-rename-tag
chmod +x git-rename-tag
sudo mv git-rename-tag /usr/local/bin/ (or add to PATH).

HISTORY

Popular third-party scripts appeared on GitHub ~2012 (e.g., mvinkus/git-rename-tag Bash version) to address frequent user requests unmet by Git core, which prioritizes tag immutability.

SEE ALSO

Copied to clipboard