Skip to main content

Function Signatures

The commit function has multiple overloads to support different usage patterns:
// Simple commit with message
function commit(
  message: string | undefined,
  description?: string
): Promise<string>

// Commit with options
function commit(
  message: string | undefined,
  opts?: CommitOptions
): Promise<string>

// Commit with message, description, and options
function commit(
  message: string | undefined,
  description?: string,
  opts?: CommitOptions
): Promise<string>
Record changes to the repository by creating a new commit with staged changes.

Parameters

message
string | undefined
required
The commit message (first line). This becomes the subject line of the commit.Can be undefined when using options like --reuse-message or --fixup.
description
string
Optional extended description for the commit. This becomes the body of the commit message.Provides additional context and details about the changes.
opts
CommitOptions
default:"{}"
Configuration options for the commit operation.

Returns

result
Promise<string>
A promise that resolves to the output from the git commit command, typically including the commit hash and summary.

Examples

Basic commits

import { add, commit } from "usegit"

// Stage and commit files
await add(".")
await commit("feat: add new API")

Commit with description

// Commit with extended description
await commit(
  "fix: handle empty input",
  "This fixes a bug where empty input caused a crash."
)

Commit with options

// Amend the last commit
await commit("chore: release", { flags: ["--amend"] })

// Commit with signoff
await commit("feat: improve API", {
  flags: ["--signoff"]
})

Commit with description and options

// All three parameters
await commit(
  "feat: improve API",
  "Adds better typing and docs.",
  { flags: ["--signoff"] }
)

Advanced options

// Commit with custom author
await commit("feat: initial import", {
  "--author": "Alice <[email protected]>"
})

// Commit with custom date
await commit("fix: backdate", {
  "--date": "2024-01-01"
})

// GPG-signed commit
await commit("feat: secure feature", {
  "--gpg-sign": true
})

// GPG-signed with specific key
await commit("feat: secure feature", {
  "--gpg-sign": "ABC123DEF456"
})

Allow empty commits

// Create commit without changes (useful for CI triggers)
await commit("chore: trigger CI", {
  flags: ["--allow-empty"]
})

Bypass hooks

// Skip pre-commit hooks
await commit("fix: urgent", {
  flags: ["--no-verify"]
})

Build docs developers (and LLMs) love