Skip to content

Git Integration ​

Whenever the current directory is inside a Git repository, @neosjs/release enables the built-in git plugin automatically (to disable it, pass --no-git or set git: false in your configuration).

Default Workflow ​

With the default configuration, the git plugin performs the following steps in order:

  1. Preflight checks (init):
    • Branch allowlist/denylist validation (git.requireBranch)
    • Clean working directory check (git.requireCleanWorkingDir)
    • Runs git fetch to sync remote references
    • Remote existence check (when git.push: true)
    • Upstream branch configuration check (git.requireUpstream)
    • Upstream sync check: blocks immediately if the local branch is behind its upstream (git.requireUpToDate)
    • Commit count check since the latest tag (git.requireCommits)
  2. Stage changes (beforeRelease):
    • Runs git add . --update (git add . --all when git.addUntrackedFiles: true is enabled)
    • When --show-changeset is passed, previews the list of files to be committed before committing (git status --short --untracked-files=no)
  3. Create commit (release):
    • git commit --message "<git.commitMessage>" [...git.commitArgs]
    • If there is nothing staged to commit, prints a warning and still tags the current latest commit
  4. Create annotated tag (release):
    • git tag --message "<git.tagAnnotation>" [...git.tagArgs] <git.tagName>
    • If the tag name is the same as latestTag and already exists, prints a warning and skips tagging
  5. Push to remote (release):
    • git push [...git.pushArgs] [<upstreamArgs>]
    • If the current branch has no upstream tracking branch yet, --set-upstream <pushRepo|origin> <branchName> is added automatically

Outside CI mode, the commit, tag, and push steps each prompt for confirmation before they run.

Preflight Checks in Detail ​

Branch Restriction (git.requireBranch) ​

Supports exact branch names, wildcards, and ! negation (powered by wildcard-match), as a single string or an array of strings:

ts
export default {
  git: {
    // Only allow releasing from main or release/* branches
    requireBranch: ['main', 'release/*']
  }
}

You can also forbid releasing directly from a branch:

ts
export default {
  git: {
    requireBranch: '!main'
  }
}

Upstream Sync Blocking (git.requireUpToDate) ​

Enabled by default (true). After git fetch, it runs git rev-list --left-right --count HEAD...@{u} to check whether the current branch is behind its upstream. If it is behind by any commit, the release stops immediately and asks you to pull first, preventing push conflicts or publishing an npm package built from outdated code.

To skip it temporarily in special cases, pass --no-git.requireUpToDate.

Commit Count Check (git.requireCommits) ​

See the recipe: Release Only on New Commits.

  • git.requireCommits: true: stops the release when there are no new commits since the latest matching tag.
  • git.requireCommitsFail: false: treats the absence of new commits as "nothing to release" and exits with code 0 (suitable for scheduled CI jobs).
  • git.commitsPath: counts only commits that changed files under the specified directory (such as packages/core).

Tag Lookup Rules ​

The following rules apply when resolving the current latest tag (latestTag):

  • By default it uses git describe --tags --match=<match> --abbrev=0 [--exclude=<exclude>], where <match> is taken from git.tagMatch if set; otherwise it is derived from git.tagName by replacing ${version} with * (v* by default).
  • When git.getLatestTagFromAllRefs: true is enabled, it uses git -c "versionsort.suffix=-" for-each-ref --count=1 --sort=-v:refname --format="%(refname:short)" refs/tags/<match> instead, picking the latest tag by semantic version across all refs (not limited to ancestor commits of the current branch).

Tag Signing ​

@neosjs/release always creates annotated tags (supporting GPG / SSH / X.509 signatures) and never passes --annotate explicitly, so it fully follows Git's own signing configuration. Whether a tag is signed is decided by two settings together:

  • Git configuration: applies to every git tag (including manual commands).
    • tag.gpgSign=true: signs all tags.
    • tag.forceSignAnnotated=true: signs annotated tags.
    • Run git config --global <name> true to apply it to all repositories; omit --global to apply it to the current repository only.
  • git.tagArgs: affects only tags created by this tool.
    • Passing --sign (or -s / -u <key>) forces signing.
    • Passing --annotate / --no-sign cancels the corresponding signing switch in the Git configuration.

The resulting behavior when both settings are present:

Git ConfigurationNo Extra Args--annotate--no-sign--sign
Neither setUnsignedUnsignedUnsignedSigned
Only tag.forceSignAnnotatedSignedUnsignedSignedSigned
Only tag.gpgSignSignedSignedUnsignedSigned
Both setSignedSignedSignedSigned

--annotate cancels only tag.forceSignAnnotated, and --no-sign cancels only tag.gpgSign. To force unsigned tags regardless of the local Git configuration, pass both: git.tagArgs: ['--annotate', '--no-sign'].

Note: putting git.tagArgs: ['--sign'] in the project configuration affects every maintainer who runs a release in the repository, and requires each of them to have a working signing key configured locally.

Signature Verification ​

In some environments (for example, when SSH signing fails on Git 2.43 and earlier), git tag does not return a non-zero exit code but silently produces an unsigned tag. After creating a tag, @neosjs/release checks the signature block with git cat-file tag <tagName>:

  • Interactive mode: prints a warning and keeps the tag. The flow continues to the push confirmation step, where you decide whether to abort or re-sign afterwards.
  • CI mode (--ci): fails immediately and deletes the unsigned tag automatically, preventing an unsigned tag from being pushed to the remote.

Automatic Rollback on Failure or Cancel ​

When git.requireCleanWorkingDir: true (the default) is enabled:

  • If an error occurs during the commit/tag stage or the user cancels the release with Ctrl+C, local changes are rolled back automatically: the created local tag is deleted, the commit is reset (git reset --hard HEAD~1 or HEAD), and tracked files such as package.json are restored.

  • If git push fails:

    • If the package has not been published to npm yet (isReleased is not true), it tries to delete the pushed remote tag (git push origin --delete <tagName>) and rolls back the local state.

    • If the package has already been published to npm (isReleased === true), the local commit and tag are not rolled back, to keep the local repository in sync with the published version. Instead, it asks you to run the following after fixing the network or permission problem:

      bash
      release --no-increment --no-npm
  • In Release-via-PR mode, the rollback checks out the original branch and restores or deletes the temporary release branch.

Configuration Options ​

OptionTypeDefaultDescription
git.logCommandstring'git log --pretty=format:"* %s (%h)" ${from}...${to}'Fallback command used to generate the commit log when the changelog plugin is disabled or produces no log. With the default value, tag names are passed to git as separate arguments; a custom value runs through the system shell, and is refused (naming the offending variable) when a tag name contains shell syntax, see logCommand and Shell
git.requireCleanWorkingDirbooleantrueRequire a clean working directory before releasing (also a prerequisite for automatic rollback)
git.requireBranchfalse | string | string[]falseRestrict releasing to matching branches (supports wildcards and ! negation)
git.requireUpstreambooleantrueRequire the current branch to have an upstream remote branch
git.requireUpToDatebooleantrueRequire the current branch not to be behind its upstream; blocks immediately when it is
git.requireCommitsbooleanfalseStop the release when there are no new commits since the latest tag
git.requireCommitsFailbooleantrueWhether to exit with a failure when there are no new commits (false ends early with exit code 0)
git.commitsPathstring''Count only commits that changed files under the given directory path (used with requireCommits)
git.addUntrackedFilesbooleanfalseWhether to include untracked files when staging (true uses --all, false uses --update)
git.commitbooleantrueSet to false to skip the commit step
git.commitMessagestring'chore: release v${version}'Commit message template
git.commitArgsstring[] | string[]Extra arguments passed to git commit
git.tagbooleantrueSet to false to skip the tag step
git.tagNamestring | null'v${version}'Git tag name template
git.tagMatchstring | nullnullMatch pattern used when looking up the latest tag (git describe --match)
git.tagExcludestring | nullnullPattern excluded when looking up the latest tag (git describe --exclude)
git.getLatestTagFromAllRefsbooleanfalseLook up the latest tag across all refs, sorted by semantic version
git.tagAnnotationstring'Release v${version}'Annotation message template for annotated tags
git.tagArgsstring[] | string[]Extra arguments passed to git tag
git.pushbooleantrueSet to false to skip the push step
git.pushArgsstring[] | string['--follow-tags']Extra arguments passed to git push (configuring it replaces the default array as a whole)
git.pushRepostring''Remote name or Git URL to push to (empty defaults to the upstream remote of the current branch or origin)

Complete Default Configuration ​

ts
{
  git: {
    logCommand: 'git log --pretty=format:"* %s (%h)" ${from}...${to}',
    requireCleanWorkingDir: true,
    requireBranch: false,
    requireUpstream: true,
    requireUpToDate: true,
    requireCommits: false,
    requireCommitsFail: true,
    commitsPath: '',
    addUntrackedFiles: false,
    commit: true,
    commitMessage: 'chore: release v${version}',
    commitArgs: [],
    tag: true,
    tagExclude: null,
    tagName: 'v${version}',
    tagMatch: null,
    getLatestTagFromAllRefs: false,
    tagAnnotation: 'Release v${version}',
    tagArgs: [],
    push: true,
    pushArgs: ['--follow-tags'],
    pushRepo: ''
  }
}

logCommand and Shell ​

The git commands built into the tool always run as argument arrays: content that comes from the repository, such as branch names and tag names, is passed to git verbatim as a single argument. It is never interpreted by a shell or evaluated by the template engine. Even if a branch or tag name contains characters such as $(...), `, ;, or ${...}, they are just part of the name. The same applies to the read-only commands that run under --dry-run.

git.logCommand is the exception: it is a shell command template that you write yourself. It is first rendered with the context (from, to, latestTag) and then handed to the system shell, so:

  • With the default value, the tool recognizes it and passes tag names to git as separate arguments.
  • Once customized, ${from} / ${to} in the template are rendered as tag names. A tag name that contains only ordinary characters (letters, digits, ., /, @, +, -, _) is rendered and executed as usual. A tag name containing any other character (whitespace, quotes, $, ;, and other shell syntax) causes the command not to run: the release fails and names the offending variable (the same rule as hooks, see Lifecycle Hooks). This prevents tag names from being executed by the shell. Keep the default value if your repository may contain such tag names.

When customizing logCommand, do not splice repository content into it in any way other than ${...}, and do not write expressions such as ${process.env.SECRET} in the template: ${...} in the template is a JavaScript expression that gets evaluated, not just a placeholder.