Package Exports
- branch-name
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (branch-name) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
branch-name 
Get the current branch name
Why?
- Clean, minimal, promise-based API.
- Respects your
$PATH. - Uses the most reliable branch detection algorithm.
- Gives you control in weird situations.
Install
npm install branch-name --saveUsage
Get it into your program.
const branchName = require('branch-name');Get the current branch name.
branchName.get().then((name) => {
console.log(name);
});Get the current branch name, but with a fallback result for detached head and non-repository situations.
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.
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
Default: process.cwd()
Directory whose branch you want determine.
Related
- head-hash - Get the current commit hash
Contributing
See our contributing guidelines for more details.
- Fork it.
- Make a feature branch:
git checkout -b my-new-feature - Commit your changes:
git commit -am 'Add some feature' - Push to the branch:
git push origin my-new-feature - Submit a pull request.
License
Go make something, dang it.