# branch-name

> Get the current branch name

Latest version **1.0.0** (published 2017-09-05) · MPL-2.0 license · 0 weekly downloads

## Install

```sh
npm install branch-name
pnpm add branch-name
yarn add branch-name
bun add branch-name
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2017-09-05 |
| First published | 2016-03-28 |
| Weekly downloads | 0 |
| License | MPL-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=8 |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Seth Holladay |
| Maintainers | sholladay |
| Keywords | git, branch, name, meta, version |

## Links

- npm: https://www.npmjs.com/package/branch-name
- Repository: https://github.com/sholladay/branch-name
- Issues: https://github.com/sholladay/branch-name/issues
- npm.io page: https://npm.io/package/branch-name

## Dependencies (1)

- [mkdirtemp](https://npm.io/package/mkdirtemp.md) ^1.1.0

## Alternatives

- [base64url](https://npm.io/package/base64url.md) — 6.1M weekly downloads
- [get-installed-path](https://npm.io/package/get-installed-path.md) — 502.9K weekly downloads
- [@uppy/url](https://npm.io/package/@uppy/url.md) — 185.8K weekly downloads
- [@d3fc/d3fc-shape](https://npm.io/package/@d3fc/d3fc-shape.md) — 16.2K weekly downloads
- [localizer](https://npm.io/package/localizer.md) — 226 weekly downloads

## Recent versions

- 1.0.0 (latest) — 2017-09-05
- 0.1.7 — 2016-08-30
- 0.1.6 — 2016-08-10
- 0.1.5 — 2016-08-08
- 0.1.4 — 2016-05-25
- 0.1.3 — 2016-04-13
- 0.1.2 — 2016-03-28
- 0.1.1 — 2016-03-28
- 0.1.0 — 2016-03-28

## README

# branch-name [![Build status for branch-name](https://img.shields.io/circleci/project/sholladay/branch-name/master.svg "Build Status")](https://circleci.com/gh/sholladay/branch-name "Builds")

> Get the current branch name

## Why?

 - Clean, minimal, promise-based API.
 - Respects your `$PATH`.
 - Uses the most reliable branch [detection algorithm](http://stackoverflow.com/a/19585361/2990144).
 - Gives you control in weird situations.

## Install

```sh
npm install branch-name --save
```

## Usage

Get it into your program.

```js
const branchName = require('branch-name');
```

Get the current branch name.

```js
branchName.get().then((name) => {
   console.log(name);
});
```

Get the current branch name, but with a fallback result for detached head and non-repository situations.

```js
branchName.assume('dev').then((name) => {
   console.log(name);  // prints current branch if possible, 'dev' otherwise
});
```

Get the current branch name, with the default `master` as a fallback.

```js
branchName.assumeMaster().then((name) => {
   console.log(name);  // prints current branch if possible, 'master' otherwise
});
```

## API

### get(option)

Returns the branch name that HEAD points to. Throws an error if not in a git repository or HEAD is not a branch.

### assume(name, option)

Similar to `.get()`, but will return `name` if not in a git repository or the HEAD is detached.

### assumeMaster(option)

Similar to `.assume()` but always uses "master" as the fallback name.

#### option

Type: `object`

##### cwd

Type: `string`<br>
Default: `process.cwd()`

Directory whose branch you want determine.

## Related

 - [head-hash](https://github.com/sholladay/head-hash) - Get the current commit hash

## Contributing

See our [contributing guidelines](https://github.com/sholladay/branch-name/blob/master/CONTRIBUTING.md "Guidelines for participating in this project") for more details.

1. [Fork it](https://github.com/sholladay/branch-name/fork).
2. Make a feature branch: `git checkout -b my-new-feature`
3. Commit your changes: `git commit -am 'Add some feature'`
4. Push to the branch: `git push origin my-new-feature`
5. [Submit a pull request](https://github.com/sholladay/branch-name/compare "Submit code to this project for review").

## License

[MPL-2.0](https://github.com/sholladay/branch-name/blob/master/LICENSE "License for branch-name") © [Seth Holladay](https://seth-holladay.com "Author of branch-name")

Go make something, dang it.

---
_Source: https://npm.io/package/branch-name · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
