Skip to content

Instantly share code, notes, and snippets.

@wosephjeber
Last active February 23, 2024 15:20
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save wosephjeber/212f0ca7fea740c3a8b03fc2283678d3 to your computer and use it in GitHub Desktop.
Save wosephjeber/212f0ca7fea740c3a8b03fc2283678d3 to your computer and use it in GitHub Desktop.
Get branch and commit names from Node (synchronously)
const { execSync } = require('child_process');
function executeGitCommand(command) {
return execSync(command)
.toString('utf8')
.replace(/[\n\r\s]+$/, '');
}
const BRANCH = executeGitCommand('git rev-parse --abbrev-ref HEAD');
const COMMIT_SHA = executeGitCommand('git rev-parse HEAD');
@RepubIique
Copy link

Wow thanks, exactly what i've been looking for

@wigqueel
Copy link

omg, thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment