Skip to content

Instantly share code, notes, and snippets.

@theamanbhargava
Created May 27, 2021 14:10
Show Gist options
  • Select an option

  • Save theamanbhargava/ef51f593659c816454406d6d48de81f7 to your computer and use it in GitHub Desktop.

Select an option

Save theamanbhargava/ef51f593659c816454406d6d48de81f7 to your computer and use it in GitHub Desktop.
try {
if(Boolean(childProcess
.execSync("git rev-parse --is-inside-work-tree 2>/dev/null")
.toString())
) {
branchName = childProcess
.execSync('git ls-remote --heads origin | grep $(git rev-parse HEAD) | cut -d / -f 3 | head -1')
.toString();
} else {
branchName = null
}
} catch (e){
console.log("couldn't get branch name from git object, check if this is a git branch")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment