A CLI for creating better commits following the conventional commits specification
A CLI for creating better commits following the conventional commits specification
A CLI for writing better commits, following the conventional commits specification.
better-branchAs a side-effect of formatting messages
Requires Node.js 20 or newer.
npm install -g better-commitsTo run the CLI in your terminal:
better-commits # Create a new commit
better-branch # Create a new branch / worktreebetter-commits will prompt a series of questions. These prompts will build a commit message, which you can preview, before confirming the commit. - To better understand these prompts and their intention, read Conventional Commits Summary
Some of the values in these prompts will be inferred by your branch name and auto populated. You can adjust this in your .better-commits.jsonc (or .better-commits.json) configuration file.
For documentation on passing commit values to better-commits via the CLI, see CLI Flags.
[!TIP] The
--no-interactiveflag, allows automated workflows or AI agents like OpenCode and Claude Code, to use better-commits to generate consistent commit messages using less tokens.Run
better-commits --help/better-branch --helpfor more information.
Your first time running better-commits, a default config will be generated in your $HOME directory, named .better-commits.jsonc (formerly .better-commits.json)
To create a repository-specific config, navigate to the root of your project.
better-commits-init.better-commits.jsoncconfirm_with_editor and overrides will prefer the global config[!NOTE]
All properties are optional and can be removed from the config. They will be replaced by the default at run-time.
- See
.better-commits.jsonin this repository as an example
…better-commits will attempt to infer the ticket/issue, commit-type, and commit scope from your branch name. It will auto populate the corresponding field if found.
Ticket / Issue-Number
STRING-NUMBER or NUMBER are at the start of the branch name or after a /Commit Type
/Commit Scope
/, -, or _TICKET-SCOPE-descriptioncustom scope option are ignored during inferenceBetter branch is a secondary feature that works with better commits
To run the CLI in your terminal:
better-branchbetter-branch will prompt for Branch or Worktree. The Worktree flow creates a folder/worktree from your branch description and a git branch inside with your full branch name.
[!NOTE]
Creating a worktree namedeverduin94/feat/TAC-123-add-worktreeswith the native git command would create a nested folder for each/.better-branchremoves the hassle by creating 1 folder while still using the full name for the branch.
[!TIP] By default,
better-branchwill create worktrees as a sibling folder. To change this, seeworktrees.base_path.
[!TIP] Use worktrees in a repository often?
You can target your main folder for worktree creation from any folder (root or sibling)
alias create_worktree='better-branch --checkout worktree --git-dir="MAIN_FOLDER/.git" --work-tree="MAIN_FOLDER"'
Configure commands to run before or after creating a branch or worktree:
{
"branch_pre_commands": ["git pull -r origin main"],
"branch_post_commands": ["npm install"],
"worktree_pre_commands": ["echo Creating {{TYPE}} for {{TICKET}}"],
"worktree_post_commands": ["npm run setup -- --ticket={{TICKET}}"],
}better-commits works with Semantic Release
If you use better-commits to create your first commit on a new branch
If you're using Github issues to track your work, and select the closes footer option when writing your commit. Github will automatically link and close that issue when your pr is merged
better-commits can append a commit trailer per commit type. This allows you to automate change logs with tools like Gitlab.
better-commits uses native git commands under the hood. So any hooks, tools, or staging should work as if it was a normal commit.
Setting confirm_with_editor=true will allow you to edit/confirm a commit with your editor.
git config --global core.editor "nvim"git config --global core.editor "code -n --wait"You can pass arguments to git through better-commits like so:
better-commits --git-dir="$HOME/.config" --work-tree="$HOME"A practical example of this would be managing dotfiles, as described in this Atlassian Article
Use CLI flags to pass commit values directly instead of answering prompts.
--no-interactive to skip prompts, confirmation, and editor flows. This is the recommended mode for OpenCode, Claude Code, and other coding agents.--dry-run to validate the generated git commit command without creating a commit.--type, --scope, --title, --body, --ticket, --closes, --deprecates, --breaking-title, --breaking-body, --deprecates-title, --deprecates-body, --custom-footer, --trailer.--user, --type, --scope, --description, --ticket, --branch-version, --checkout.--no-interactiveExamples
better-commits --no-interactive --dry-run --type feat --scope cli --title "add parser"
better-branch --no-interactive --type feat --scope cli --ticket TAC-123 --description "add parser" --checkout worktreeTTY initialization failed: uv_tty_init returned EBADF (bad file descriptor). This may happen because you're running something like git-bash on Windows. Try another terminal/command-prompt or winpty to see if its still an issue.
If you are having issues with multilines for commits on windows, you can override the shell via your .better-commits.jsonc config.
Example
"overrides": {
"shell": "c:\\Program Files\\Git\\bin\\bash.exe"
}No open issues yet, or sync has not completed.