Get synchronously the current branch name
$ npm i current-git-branch --save
or
$ yarn add current-git-branch
Returns:
false
: It is not a git repositoryconst branchName = require('current-git-branch');
branchName(); // false or branch name of process.cwd()
branchName({ altPath: 'any/git/repo' }); // false or branch name of the directory 'any/git/repo'
branchName({ altPath: 'any/git/repo', branchOptions: [ "--no-color" ] }); // alternatively, you may pass git-branch command options, either as a string or an array
MIT © Jan Peer Stöcklmair