This is a library designed to be able to be included via NuGet which returns the current branch as a JSON object such as:
{ "branch": "master" }
This is mainly designed for applications that may require branch name in this format such as Terraform.
The package available here may work, it may not. I recommend you use the official nuget package source and install as follows.
Install-Package BranchFinder
dotnet add package BranchFinder