https://github.com/lcluber/gitbranchvalidator
Git branch name validator on Git hooks for clean workflow
https://github.com/lcluber/gitbranchvalidator
branch git hook husky pre-commit validation
Last synced: 5 months ago
JSON representation
Git branch name validator on Git hooks for clean workflow
- Host: GitHub
- URL: https://github.com/lcluber/gitbranchvalidator
- Owner: LCluber
- License: mit
- Created: 2019-10-13T10:05:49.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-04T22:59:10.000Z (over 3 years ago)
- Last Synced: 2025-04-14T16:53:26.325Z (about 1 year ago)
- Topics: branch, git, hook, husky, pre-commit, validation
- Language: JavaScript
- Homepage:
- Size: 848 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 15
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
### This project has been transferred to [DWTechs](https://github.com/DWTechs/GitBranchValidator).
### Please update your project dependencies to the latest version [on the new repository](https://github.com/DWTechs/GitBranchValidator).
[](https://opensource.org/licenses/MIT)
[](https://www.npmjs.com/package/@lcluber/gitbranchvalidator)

- [Synopsis](#synopsis)
- [Motivation](#motivation)
- [Installation](#installation)
- [npm](#npm)
- [Yarn](#yarn)
- [Local](#local)
- [Usage](#usage)
- [Command line](#command-line)
- [Pattern](#pattern)
- [Workflow integration](#workflow-integration)
- [Contributors](#contributors)
- [License](#license)
- [Stack](#stack)
## Synopsis
**[GitBranchValidator](https://github.com/LCluber/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](https://dwtechs.github.io/efficient-git/branch/).
You can also set your own rules using a [custom pattern](#pattern).
## Installation
### npm
```bash
$ npm i @lcluber/gitbranchvalidator -g
```
### Yarn
```bash
$ 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.
```bash
$ npm i @lcluber/gitbranchvalidator --save-dev
```
```bash
$ yarn add @lcluber/gitbranchvalidator --dev
```
## Usage
### Command line
```bash
$ cd
$ gbvalidator
```
Alternatively if you did not install GitBranchValidator globally you can use npx.
```bash
$ npx gbvalidator
```
Or as an npm script in your 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](https://dwtechs.github.io/efficient-git/branch/).
You can use your own custom pattern by adding an optional regexp :
```bash
$ cd
$ 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 :
```bash
$ cd
$ gbvalidator --message "You can learn more about branch name conventions of this project on https://dwtechs.github.io/efficient-git/branch/"
```
### Workflow integration
Validate branch name on pre-commit with Husky :
```bash
$ npm install husky --save-dev
```
```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](https://github.com/LCluber/GitBranchValidator/blob/master/NOTICE.md)** for detailed installation guide.
## License
**[MIT](https://github.com/LCluber/GitBranchValidator/blob/master/LICENSE)**
## Stack
| Purpose | Choice | Motivation |
| :-------------- | :----------------------------------: | ---------------------------------------------------------: |
| repository | [Github](https://github.com/) | hosting for software development version control using Git |
| package manager | [npm](https://www.npmjs.com/get-npm) | default node.js package manager |
| unit testing | [Jest](https://jestjs.io/) | delightful testing with a focus on simplicity |