Git branch name validator
npm install validate-branch-name




[![Known Vulnerabilities][snyk-image]][snyk-url]
[![npm download][download-image]][download-url]
!npm
[snyk-image]: https://snyk.io/test/npm/validate-branch-name/badge.svg?style=flat-square
[snyk-url]: https://snyk.io/test/npm/validate-branch-name
[download-image]: https://img.shields.io/npm/dm/validate-branch-name.svg?style=flat-square
[download-url]: https://npmjs.org/package/validate-branch-name
Git branch name validator.
validate-branch-name can be used through command line directly. When using with Husky, you should make sure husky version >= v1.0.0.
``bashlocal install
$ npm i validate-branch-name -D
`
Use through command line
`shell
npx validate-branch-name
`
Use with husky
First way:
Configure hooks and pattern using package.json.
`js`
// {app_root}/package.json
{
"husky": {
"hooks": {
"pre-commit": "npx validate-branch-name"
}
},
"validate-branch-name": {
"pattern": "^(master|main|develop){1}$|^(feature|fix|hotfix|release)\/.+$",
"errorMsg": "your own error message"
}
}
Second way:
Define pre-commit file under .husky directory.
`shell
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
npx validate-branch-name
`
We have set pattern and errorMsg by default, but you can still defined them as you like.
Default pattern: ^(master|main|develop){1}$|^(feature|fix|hotfix|release)\/.+$
Example: feature/test/pattern-test would be passed.
Available patterns:
- ^(feature|fix|hotfix|release)\/.+ - branch has to start with _feature/, fix/, release/ or hotfix/_
* (feature|release|hotfix)\/(JIRA-\d+) - it should look like _feature/JIRA-1234_
- (feature|release|hotfix)\/(JIRA-\d+\/)?[a-z-]+ - it should look like _feature/branch-name_ or include JIRA's code like _feature/JIRA-1234/branch-name_
- custom patterns, visit regex.
**You can also use .validate-branch-namerc, .validate-branch-namerc.json, .validate-branch-namerc.yaml, .validate-branch-namerc.yml, .validate-branch-namerc.js, .validate-branch-namerc.cjs, validate-branch-name.config.js or validate-branch-name.config.cjs` file to define config.**
Please open an issue here.