is-git-branch-name-valid
Version:
Check that a git branch name is well formed
42 lines (27 loc) • 1.16 kB
Markdown
**Check that a git branch name is well formed.**
[](https://www.npmjs.org/package/is-git-branch-name-valid)
[](https://www.npmjs.org/package/is-git-branch-name-valid)

[](https://standardjs.com)
```js
const validBranch = require('is-git-branch-name-valid')
validBranch('foo.bar') // true
validBranch('foo-bar/baz') // true
validBranch('foo^bar') // false
validBranch('HEAD') // false
validBranch('-foo') // false
```
Takes a string `name`. Returns true if `name`:
1. Is a [valid reference name](https://github.com/vweevers/is-git-ref-name-valid)
2. Does not equal `HEAD` or start with `-`.
With [npm](https://npmjs.org) do:
```
npm install is-git-branch-name-valid
```
[](LICENSE) © Vincent Weevers