How can I get the current git branch with node.js without an external library? I need to be able to grab the current branch name to perform another function in my node file.
Update with partially working code
I'm able to get the branch name with this, but can't seem to log out a message if the stdout
matches the given string.
const { exec } = require('child_process');
exec('git rev-parse --abbrev-ref HEAD', (err, stdout, stderr) => {
if (stdout === 'name-of-branch') {
console.log(this is the correct branch);
}
});