1

I need to know which branch is currently checked out.

One solution I see is to list branches and check which one '===' current 'HEAD'. Is there another way ?

Anna B
  • 5,997
  • 5
  • 40
  • 52

1 Answers1

4

Use this code:

import * as Git from 'nodegit';

let repo: Git.Repository = await Git.Repository.open("path to the repo");

let currentBranch: Git.Reference = await repo.getCurrentBranch();

let currentBranchName: string = currentBranch.shorthand();
Yannis
  • 1,682
  • 7
  • 27
  • 45
Rachit
  • 63
  • 6