Skip to main content
The useGit library provides several convenience functions that wrap the main commit function with commonly used options.

commitAll

Commit all tracked changes without explicitly staging them first.

Function Signature

function commitAll(
  message: string,
  description?: string
): Promise<string>

Parameters

message
string
required
The commit message.
description
string
Optional extended description.

Returns

result
Promise<string>
A promise that resolves to the output from the commit command.

Example

import { commitAll } from "usegit"

// Automatically stage all tracked files and commit
await commitAll("chore: update deps")

// With description
await commitAll(
  "refactor: restructure modules",
  "Moved components to separate directories for better organization."
)

When to use

Use commitAll when you want to commit all modified tracked files without manually calling add() first. This is equivalent to git commit -a. Note: This does not add untracked files. Only modifications to tracked files are included.

commitAmend

Amend the last commit with new changes or a modified message.

Function Signature

function commitAmend(
  message?: string,
  description?: string
): Promise<string>

Parameters

message
string
Optional new commit message. If omitted, keeps the existing message.
description
string
Optional extended description.

Returns

result
Promise<string>
A promise that resolves to the output from the commit command.

Example

import { add, commitAmend } from "usegit"

// Fix a typo in the last commit message
await commitAmend("fix: typo in component")

// Add forgotten files to last commit
await add(["src/forgotten.ts"])
await commitAmend() // Keeps existing message

When to use

Use commitAmend to:
  • Fix typos in the last commit message
  • Add forgotten files to the last commit
  • Modify the last commit before pushing
Warning: Never amend commits that have been pushed to a shared repository, as this rewrites history.

commitEmpty

Create an empty commit with no changes.

Function Signature

function commitEmpty(message: string): Promise<string>

Parameters

message
string
required
The commit message.

Returns

result
Promise<string>
A promise that resolves to the output from the commit command.

Example

import { commitEmpty } from "usegit"

// Trigger CI without actual changes
await commitEmpty("chore: trigger CI")

// Mark a milestone
await commitEmpty("milestone: v2.0.0 planning complete")

When to use

Use commitEmpty to:
  • Trigger CI/CD pipelines
  • Mark milestones or checkpoints
  • Test commit hooks
  • Create placeholder commits in a branch

commitFixup

Create a fixup commit for autosquash during interactive rebase.

Function Signature

function commitFixup(commitId: string): Promise<string>

Parameters

commitId
string
required
The commit hash to create a fixup for.

Returns

result
Promise<string>
A promise that resolves to the output from the commit command.

Example

import { add, commitFixup } from "usegit"

// Create fixup commit for a previous commit
await add(["src/bug-fix.ts"])
await commitFixup("abc123")

// Later, during interactive rebase:
// git rebase -i --autosquash main

When to use

Use commitFixup when you need to fix a bug or issue in a previous commit during a feature branch. The fixup commit will be automatically squashed into the target commit when you run git rebase -i --autosquash. This is particularly useful for:
  • Fixing issues found during code review
  • Making corrections to commits before merging
  • Maintaining a clean commit history

commitNoEdit

Amend the last commit without editing the message and without staging new changes.

Function Signature

function commitNoEdit(): Promise<string>

Returns

result
Promise<string>
A promise that resolves to the output from the commit command.

Example

import { add, commitNoEdit } from "usegit"

// Add forgotten files and amend without changing message
await add(["src/forgotten.ts"])
await commitNoEdit()

When to use

Use commitNoEdit when you need to add staged changes to the last commit but want to keep the existing commit message unchanged. This is a shortcut for git commit --amend --no-edit. Common scenarios:
  • Adding forgotten files to the last commit
  • Including additional changes in the last commit
  • Updating the commit without triggering an editor

commitReuseMessage

Reuse the commit message and authorship from an existing commit.

Function Signature

function commitReuseMessage(commitId: string): Promise<string>

Parameters

commitId
string
required
The commit hash to reuse the message from.

Returns

result
Promise<string>
A promise that resolves to the output from the commit command.

Example

import { add, commitReuseMessage } from "usegit"

// Make similar changes and reuse the message
await add(["src/another-fix.ts"])
await commitReuseMessage("abc123")

When to use

Use commitReuseMessage when you need to:
  • Apply similar changes as a previous commit
  • Recreate a commit after rebasing or cherry-picking
  • Use a well-crafted message from another commit
This copies both the commit message and the author information from the specified commit.

commitSignoff

Commit with a Signed-off-by trailer added to the commit message.

Function Signature

function commitSignoff(
  message: string,
  description?: string
): Promise<string>

Parameters

message
string
required
The commit message.
description
string
Optional extended description.

Returns

result
Promise<string>
A promise that resolves to the output from the commit command.

Example

import { add, commitSignoff } from "usegit"

// Commit with signoff
await add(".")
await commitSignoff("feat: add API endpoint")

// The commit message will include:
// feat: add API endpoint
//
// Signed-off-by: Your Name <[email protected]>

When to use

Use commitSignoff when contributing to projects that require a Developer Certificate of Origin (DCO). The signoff certifies that you wrote the code or have the right to submit it. Many open source projects require signoff for legal and compliance reasons, including:
  • Linux kernel
  • Many Apache Foundation projects
  • Projects following the DCO process

commitWithAuthor

Commit with an explicit author different from the committer.

Function Signature

function commitWithAuthor(
  message: string,
  author: string,
  description?: string
): Promise<string>

Parameters

message
string
required
The commit message.
author
string
required
The author in the format "Name <email>".
description
string
Optional extended description.

Returns

result
Promise<string>
A promise that resolves to the output from the commit command.

Example

import { add, commitWithAuthor } from "usegit"

// Commit code written by someone else
await add(".")
await commitWithAuthor(
  "feat: initial import",
  "Alice <[email protected]>"
)

// With description
await commitWithAuthor(
  "fix: resolve merge conflict",
  "Bob <[email protected]>",
  "Applied Bob's fix after manual merge."
)

When to use

Use commitWithAuthor when you need to:
  • Commit code written by someone else (e.g., pair programming)
  • Import historical commits preserving original authorship
  • Apply patches from contributors who don’t have direct access
  • Maintain accurate attribution in collaborative projects
Note: The committer will still be you (the person running the command), but the author field will reflect the specified author.

Build docs developers (and LLMs) love