Get the current branch name
npm install branch-name> Get the current branch name
- Clean, minimal, promise-based API.
- Respects your $PATH.
- Uses the most reliable branch detection algorithm.
- Gives you control in weird situations.
``sh`
npm install branch-name --save
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
});
Returns the branch name that HEAD points to. Throws an error if not in a git repository or HEAD is not a branch.
Similar to .get(), but will return name if not in a git repository or the HEAD is detached.
Similar to .assume() but always uses "master" as the fallback name.
#### option
Type: object
##### cwd
Type: stringprocess.cwd()
Default:
Directory whose branch you want determine.
- head-hash - Get the current commit hash
See our contributing guidelines for more details.
1. Fork it.
2. Make a feature branch: git checkout -b my-new-featuregit commit -am 'Add some feature'
3. Commit your changes: git push origin my-new-feature`
4. Push to the branch:
5. Submit a pull request.
Go make something, dang it.