npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

branch-name-lint

v3.0.1

Published

Lint your branch names

Downloads

43,048

Readme

branch-name-lint Build Status Known Vulnerabilities npm

Validating and linting the git branch name. Create a config file or use the default configuration file. Use it in husky config file to make sure that your branch will not be rejected by some pesky Jenkins branch name conventions. You may use it as part of a CI process or just as an handy npx command.

Install

$ npm install branch-name-lint

CLI usage

$ npx branch-name-lint
$ npx branch-name-lint --help

  Usage
    npx branch-name-lint [configfileLocation JSON|JS]

  Options
    --help   - to get this screen
    --branch - specify a custom branch name to check instead of the current git branch

  Examples
    $ branch-name-lint
    $ branch-name-lint config-file.json
    $ branch-name-lint config-file.js
    $ branch-name-lint --branch feature/my-new-feature

CLI options.json

Any Valid JSON file with branchNameLinter attribute.

{
    "branchNameLinter": {
        "prefixes": [
            "feature",
            "hotfix",
            "release"
        ],
        "suggestions": {
            "features": "feature",
            "feat": "feature",
            "fix": "hotfix",
            "releases": "release"
        },
        "banned": [
            "wip"
        ],
        "skip": [
            "skip-ci"
        ],
        "disallowed": [
            "master",
            "develop",
            "staging"
        ],
        "separator": "/",
        "branchNameEnvVariable": false,
        "branch": false,
        "msgBranchBanned": "Branches with the name \"%s\" are not allowed.",
        "msgBranchDisallowed": "Pushing to \"%s\" is not allowed, use git-flow.",
        "msgPrefixNotAllowed": "Branch prefix \"%s\" is not allowed.",
        "msgPrefixSuggestion": "Instead of \"%s\" try \"%s\".",
        "msgSeparatorRequired": "Branch \"%s\" must contain a separator \"%s\"."
    }
}

Specifying a Custom Branch Name

You can specify a custom branch name to validate instead of using the current git branch in two ways:

  1. Using the CLI flag:

    $ npx branch-name-lint --branch feature/my-custom-branch
  2. Using configuration:

    {
      "branchNameLinter": {
        "branch": "feature/my-custom-branch"
      }
    }
  3. Using an environment variable:

    {
      "branchNameLinter": {
        "branchNameEnvVariable": "CI_BRANCH_NAME"
      }
    }

    Then set the environment variable:

    CI_BRANCH_NAME=feature/my-custom-branch npx branch-name-lint

This is useful for CI/CD environments where you might want to validate branch names from environment variables.

Disabling Checks

You can disable prefix or separator checks by setting their respective configuration values to false:

{
    "branchNameLinter": {
        "prefixes": false,  // Disables the prefix validation check
        "separator": false, // Disables the separator validation check
        "regex": "^(revert|master|develop|issue|release|hotfix/|feature/|support/|shift-)"
    }
}

When prefixes is set to false, any branch prefix will be allowed. When separator is set to false, branches without separators will be allowed.

CLI options.js

You can also use a JavaScript file for configuration, which allows for more dynamic configuration with variables and imports:

// config-file.js
// Define constants that can be reused 
const COMMON_PREFIXES = ['feature', 'bugfix', 'hotfix', 'release'];
const CI_PREFIXES = ['ci', 'build'];

// Combine arrays for configuration
const ALL_PREFIXES = [...COMMON_PREFIXES, ...CI_PREFIXES];

// Export the configuration object
module.exports = {
  prefixes: ALL_PREFIXES, // Set to false to disable prefix check
  suggestions: {
    feat: 'feature'
  },
  banned: ['wip', 'tmp'],
  skip: ['develop', 'master', 'main'],
  separator: '/', // Set to false to disable separator check
  disallowed: ['master', 'develop', 'main'],
  // other options...
};

Usage with regex

In order to check the branch name with a regex you can add a a regex as a string under the branchNameLinter in your config JSON. You can also pass any options for the regex (e.g. case insensitive: 'i')

{
    "branchNameLinter": {
		"regex": "^([A-Z]+-[0-9]+.{5,70})",
        "regexOptions": "i",
		...
        "msgDoesNotMatchRegex": 'Branch "%s" does not match the allowed pattern: "%s"'
	}
}

Husky usage

After installation, just add in any husky hook as node modules call.

"husky": {
    "hooks": {
        "pre-push": "npx branch-name-lint [sample-configuration.json]"
    }
},

Or with a JavaScript configuration file:

"husky": {
    "hooks": {
        "pre-push": "npx branch-name-lint [sample-configuration.js]"
    }
},

GitHub Actions Usage

You can integrate branch-name-lint into your GitHub Actions workflows to enforce branch naming conventions across your team. This is especially useful for maintaining consistent branch naming in collaborative projects.

Basic Example

Create a workflow file at .github/workflows/branch-name-lint.yml:

name: Branch Name Lint

on:
  push:
    branches-ignore:
      - main
      - master
  pull_request:
    branches:
      - main
      - master

jobs:
  lint-branch-name:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-node@v3
        with:
          node-version: '18'
      - run: npm install branch-name-lint --no-save
      - name: Extract branch name
        shell: bash
        run: |
          if [ "${{ github.event_name }}" == "pull_request" ]; then
            # For pull requests, use the head branch name
            echo "BRANCH_NAME=${{ github.head_ref }}" >> $GITHUB_ENV
          else
            # For pushes, extract from GITHUB_REF
            echo "BRANCH_NAME=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV
          fi
      - name: Check branch name
        run: npx branch-name-lint
        env:
          BRANCH_NAME: ${{ env.BRANCH_NAME }}

Advanced Example with Custom Configuration

For more advanced use cases, create a custom configuration file:

  1. First, create a config file at .github/branch-name-lint.json:
{
  "branchNameLinter": {
    "prefixes": [
      "feature",
      "hotfix",
      "release",
      "docs",
      "chore",
      "fix",
      "ci",
      "test"
    ],
    "suggestions": {
      "features": "feature",
      "feat": "feature", 
      "fix": "hotfix", 
      "releases": "release"
    },
    "banned": ["wip"],
    "skip": ["main", "master", "develop", "staging"],
    "disallowed": [],
    "separator": "/",
    "branchNameEnvVariable": "BRANCH_NAME",
    "msgBranchBanned": "Branches with the name \"%s\" are not allowed.",
    "msgPrefixNotAllowed": "Branch prefix \"%s\" is not allowed.",
    "msgPrefixSuggestion": "Instead of \"%s\" try \"%s\".",
    "msgSeparatorRequired": "Branch \"%s\" must contain a separator \"%s\"."
  }
}
  1. Then reference this configuration in your workflow:
name: Branch Name Lint

on:
  push:
    branches-ignore:
      - main
      - master
  pull_request:
    branches:
      - main
      - master

jobs:
  lint-branch-name:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-node@v3
        with:
          node-version: '18'
      - run: npm install branch-name-lint --no-save
      - name: Extract branch name
        shell: bash
        run: |
          if [ "${{ github.event_name }}" == "pull_request" ]; then
            echo "BRANCH_NAME=${{ github.head_ref }}" >> $GITHUB_ENV
          else
            echo "BRANCH_NAME=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV
          fi
      - name: Check branch name
        run: npx branch-name-lint .github/branch-name-lint.json
        env:
          BRANCH_NAME: ${{ env.BRANCH_NAME }}

Handling Different Operating Systems

When using branch-name-lint in a matrix strategy with multiple operating systems, ensure you use environment variables in a cross-platform way:

jobs:
  lint-branch-name:
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [ubuntu-latest, windows-latest, macos-latest]
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-node@v3
        with:
          node-version: '18'
      - run: npm install branch-name-lint --no-save
      - name: Extract branch name
        shell: bash
        run: |
          if [ "${{ github.event_name }}" == "pull_request" ]; then
            echo "BRANCH_NAME=${{ github.head_ref }}" >> $GITHUB_ENV
          else
            echo "BRANCH_NAME=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV
          fi
      - name: Check branch name
        run: npx branch-name-lint .github/branch-name-lint.json
        env:
          BRANCH_NAME: ${{ env.BRANCH_NAME }}

This setup ensures that your branch naming conventions are enforced consistently across all contributions to your repository.

Usage in Node.js

const branchNameLint = require('branch-name-lint');

branchNameLint();
//=> 1 OR 0.

API

branchNameLint([options])

options

Type: object Default:

{
  prefixes: ['feature', 'hotfix', 'release'],
  suggestions: {features: 'feature', feat: 'feature', fix: 'hotfix', releases: 'release'},
  banned: ['wip'],
  skip: [],
  disallowed: ['master', 'develop', 'staging'],
  separator: '/',
  msgBranchBanned: 'Branches with the name "%s" are not allowed.',
  msgBranchDisallowed: 'Pushing to "%s" is not allowed, use git-flow.',
  msgPrefixNotAllowed: 'Branch prefix "%s" is not allowed.',
  msgPrefixSuggestion: 'Instead of "%s" try "%s".',
  msgSeparatorRequired: 'Branch "%s" must contain a separator "%s".'
}

License

MIT © Ran Bar-Zik