Skip to main content

Overview

The tag() function is a flexible low-level utility for working with Git tags. It provides direct access to the git tag command with all its options.

Syntax

function tag(opts?: TagOptions): Promise<string>
function tag(tagName: string, opts?: TagOptions): Promise<string>

Parameters

tagName
string
The name of the tag to create or operate on.
opts
TagOptions
Configuration options for the tag operation.

Returns

result
Promise<string>
A promise that resolves with the command output.

Examples

List all tags

const tags = await tag()
console.log(tags)
// Output: List of all tags in the repository

Create a lightweight tag

await tag("v1.0.0")
// Same as: git tag v1.0.0

Create an annotated tag

await tag("v1.0.0", {
  "--message": "Initial stable release",
})
// Same as: git tag -m "Initial stable release" v1.0.0

List tags with options

const sortedTags = await tag({
  flags: ["--list"],
  "--sort": "version:refname",
})
console.log(sortedTags)

Delete a tag using options

await tag({
  "--delete": "v1.0.0",
})
// Same as: git tag --delete v1.0.0

Notes

  • For most use cases, consider using the higher-level functions like createTag(), createAnnotatedTag(), or deleteTag() instead
  • The function provides direct access to git tag command options for advanced scenarios
  • When called without arguments, it lists all tags in the repository

Build docs developers (and LLMs) love