title: Get current git branch with node.js
body: <p>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.</p>
  
  <p><strong>Update with partially working code</strong></p>
  
  <p>I'm able to get the branch name with this, but can't seem to log out a message if the <code>stdout</code> matches the given string.</p>
  
  <pre><code>const { exec } = require('child_process');
  exec('git rev-parse --abbrev-ref HEAD', (err, stdout, stderr) =&gt; {
      if (stdout === 'name-of-branch') {
          console.log(this is the correct branch);
      }
  });
  </code></pre>