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:
- Preflight checks (
init):- Branch allowlist/denylist validation (
git.requireBranch) - Clean working directory check (
git.requireCleanWorkingDir) - Runs
git fetchto 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)
- Branch allowlist/denylist validation (
- Stage changes (
beforeRelease):- Runs
git add . --update(git add . --allwhengit.addUntrackedFiles: trueis enabled) - When
--show-changesetis passed, previews the list of files to be committed before committing (git status --short --untracked-files=no)
- Runs
- 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
- Create annotated tag (
release):git tag --message "<git.tagAnnotation>" [...git.tagArgs] <git.tagName>- If the tag name is the same as
latestTagand already exists, prints a warning and skips tagging
- 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:
export default {
git: {
// Only allow releasing from main or release/* branches
requireBranch: ['main', 'release/*']
}
}You can also forbid releasing directly from a branch:
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 code0(suitable for scheduled CI jobs).git.commitsPath: counts only commits that changed files under the specified directory (such aspackages/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 fromgit.tagMatchif set; otherwise it is derived fromgit.tagNameby replacing${version}with*(v*by default). - When
git.getLatestTagFromAllRefs: trueis enabled, it usesgit -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> trueto apply it to all repositories; omit--globalto 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-signcancels the corresponding signing switch in the Git configuration.
- Passing
The resulting behavior when both settings are present:
| Git Configuration | No Extra Args | --annotate | --no-sign | --sign |
|---|---|---|---|---|
| Neither set | Unsigned | Unsigned | Unsigned | Signed |
Only tag.forceSignAnnotated | Signed | Unsigned | Signed | Signed |
Only tag.gpgSign | Signed | Signed | Unsigned | Signed |
| Both set | Signed | Signed | Signed | Signed |
--annotatecancels onlytag.forceSignAnnotated, and--no-signcancels onlytag.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~1orHEAD), and tracked files such aspackage.jsonare restored.If
git pushfails:If the package has not been published to npm yet (
isReleasedis nottrue), 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:bashrelease --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
| Option | Type | Default | Description |
|---|---|---|---|
git.logCommand | string | '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.requireCleanWorkingDir | boolean | true | Require a clean working directory before releasing (also a prerequisite for automatic rollback) |
git.requireBranch | false | string | string[] | false | Restrict releasing to matching branches (supports wildcards and ! negation) |
git.requireUpstream | boolean | true | Require the current branch to have an upstream remote branch |
git.requireUpToDate | boolean | true | Require the current branch not to be behind its upstream; blocks immediately when it is |
git.requireCommits | boolean | false | Stop the release when there are no new commits since the latest tag |
git.requireCommitsFail | boolean | true | Whether to exit with a failure when there are no new commits (false ends early with exit code 0) |
git.commitsPath | string | '' | Count only commits that changed files under the given directory path (used with requireCommits) |
git.addUntrackedFiles | boolean | false | Whether to include untracked files when staging (true uses --all, false uses --update) |
git.commit | boolean | true | Set to false to skip the commit step |
git.commitMessage | string | 'chore: release v${version}' | Commit message template |
git.commitArgs | string[] | string | [] | Extra arguments passed to git commit |
git.tag | boolean | true | Set to false to skip the tag step |
git.tagName | string | null | 'v${version}' | Git tag name template |
git.tagMatch | string | null | null | Match pattern used when looking up the latest tag (git describe --match) |
git.tagExclude | string | null | null | Pattern excluded when looking up the latest tag (git describe --exclude) |
git.getLatestTagFromAllRefs | boolean | false | Look up the latest tag across all refs, sorted by semantic version |
git.tagAnnotation | string | 'Release v${version}' | Annotation message template for annotated tags |
git.tagArgs | string[] | string | [] | Extra arguments passed to git tag |
git.push | boolean | true | Set to false to skip the push step |
git.pushArgs | string[] | string | ['--follow-tags'] | Extra arguments passed to git push (configuring it replaces the default array as a whole) |
git.pushRepo | string | '' | Remote name or Git URL to push to (empty defaults to the upstream remote of the current branch or origin) |
Complete Default Configuration
{
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 ashooks, 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.