Skip to content

Instantly share code, notes, and snippets.

@wosephjeber
Last active June 5, 2024 15:33
Show Gist options
  • 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