git-mktag - Linux


Overview

git-mktag creates or updates an annotated tag object and associates it with the current HEAD commit. Tags are used to mark specific versions of the repository and allow for easy referencing later on.

Syntax

git mktag [options] <tagname> [commit-ish]

Options/Flags

  • -m, --message: Specify a message for the tag annotation. If not given, a default message will be used.
  • -f, --force: Force creation or update of the tag, even if it already exists.
  • -s, --sign: Sign the tag with the GPG key associated with the user’s email address.
  • -a, --author=<author>: Use the given string as the author of the tag annotation. Defaults to the current user’s name and email.

Examples

  • Create a lightweight tag named "v1.0" on the current HEAD commit:

    git mktag v1.0
    
  • Create a signed annotated tag named "v2.0" with a custom message:

    git mktag -m "Release version 2.0" -s v2.0
    
  • Forcefully update an existing tag:

    git mktag -f v1.0
    

Common Issues

  • Error: tag ‘v1.0’ already exists: This error occurs when you try to create a tag with the same name as an existing one. Use the -f flag to force the creation.
  • No GPG key found: If you try to sign a tag without a GPG key associated with your email address, you will encounter this error. First, generate a GPG key and associate it with your email.

Integration

  • git checkout: Use tags to quickly switch between different versions of the repository.
  • git tag -l: List all existing tags.
  • git describe: Show the latest tag and its associated commits.

Related Commands

  • git tag: Creates, deletes, and lists tags.
  • git describe: Describes the current HEAD commit with the nearest tag and commit hash.
  • git reflog: Provides a history of tag creation and modification.