Skip to content
Tutorials Center
My learning

Topics

Git Reference ยท Plumbing Commands

git mktag command

Reference for git mktag: create an annotated tag object from stdin, learn the required header lines, how validation fails, and how to point a ref at the new tag.

git mktag reads the text of a tag object from standard input, checks that it is well formed, stores it in the object database and prints its ID. It is the plumbing behind annotated tags: git tag -a writes the same kind of object, but also creates the refs/tags/<name> reference for you. mktag does not create any reference.

Since Git 2.26 the check is strict: the same rules as git fsck apply, and the object named in the header must exist and have the type you declare. That makes mktag a safe way to produce tags in scripts.

Terminal
git mktag < tag-text

Try it

Bash Build an annotated tag by hand

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Bash Validation rejects a wrong type

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Syntax

Terminal
git mktag

The command takes no options; strict checking is always on. The input format is:

TEXT
object <40-hex object id>
type <commit|tree|blob|tag>
tag <tag name>
tagger <name> <email> <unix-seconds> <timezone>

<message>
Header Description
object The ID of the tagged object. It must exist in the repository.
type The real type of that object. A mismatch is an error.
tag The tag name. It must be a valid ref component (see git check-ref-format).
tagger Identity and timestamp. Must follow the Name <email> seconds +hhmm format.

Returns: the new tag object's ID.

Errors: exit code 128 with a message such as "tagged as 'tree', but is a 'commit' type" or an fsck-style message for malformed headers.

Usage notes

  • No reference is created. Use git update-ref refs/tags/<name> <id> to publish the tag; without it, the object is unreachable and may be pruned.
  • The tagger line is the same format as in a commit. The time is Unix seconds, not an ISO date.
  • Tags can point at tags. Set type tag to build a chain; git rev-parse v1^{} peels all the way down.
  • Signing: a signed tag contains a PGP or SSH signature appended to the message. git tag -s does this for you; mktag stores whatever message you supply.
  • Compare with git tag -a: the porcelain command fills in the tagger from your config and the time from the clock, opens an editor if needed, and updates the ref. Use mktag when you need exact control.