Skip to content
master
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
bin
 
 
lib
 
 
sh
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

License: MIT npm version Jest:coverage

Synopsis

GitBranchValidator is an open source git branch name validator library.

Motivation

The goal of this library is to provide an easy way to check if the current branch name is valid before pushing it to the remote.

It's a good way to help developers keep their branch names clean on the repository and facilitate the workflow of a project with strict naming rules.

The default pattern follows the principles described here.

But you can set your own rules using a custom pattern.

Installation

npm

$ npm i @lcluber/gitbranchvalidator -g

Yarn

$ yarn add @lcluber/gitbranchvalidator -g

Locally

Alternatively, if you are planning to use GitBranchValidator within your npm package only or with npx you can install it as a devDependency in your project.

$ npm i @lcluber/gitbranchvalidator --save-dev
$ yarn add @lcluber/gitbranchvalidator --dev

Usage

Command line

$ cd <git-project>
$ gbvalidator

Alternatively if you did not install GitBranchValidator globally you can use npx.

$ npx gbvalidator

Or as an npm script in your package.

// package.json
{
  "scripts": {
    "commit": "gbvalidator"
  }
}

Pattern

  • Default : /^(feature|bugfix|release|hotfix|refactor|test|doc|build)/([a-z0-9_#-./]){3,40}$/

The default pattern follows the principles described here.

You can use your own custom pattern by adding an optional regexp :

$ cd <git-project>
$ gbvalidator --pattern "^(feat|fix)\/([a-z0-9_#-\.\/]){3,50}$"

If you use this option for a npm command in package.json, you may need to properly escape your regex in order to get a valid JSON file.

Message

You can customize the end of the error message :

$ cd <git-project>
$ gbvalidator --message "You can learn more about branch name conventions of this project on https://lcluber.github.io/LeadDevToolkit/git/BRANCH.html"

Workflow integration

Validate branch name on pre-commit with Husky :

$ npm install husky --save-dev
// package.json
{
  "husky": {
    "hooks": {
      "pre-commit": "gbvalidator"
    }
  }
}

options

Option Alias Type description
--pattern -p string to use a custom regex
--message -m string to add a custom message at the end of the error message
--help -h boolean to learn about library usage

Contributors

GitBranchValidator is still in development and I would be glad to get all the help you can provide for this project. To contribute please read NOTICE.md for detailed installation guide.

License

MIT

Stack

Purpose Choice Motivation
repository Github hosting for software development version control using Git
package manager npm default node.js package manager
unit testing Jest delightful testing with a focus on simplicity
deployment Travis test and deploy with confidence