如何使用LibGit2Sharp获取当前/活动分支?

Sim*_*mon 16 .net git libgit2sharp

所以使用LibGit2Sharp https://github.com/libgit2/libgit2sharp你可以像这样走过分支

using (var repo = new Repository(@"path to .git"))
{
    foreach (var branch in repo.Branches)
    {
        Debug.WriteLine(branch.Name);   
    }
}
Run Code Online (Sandbox Code Playgroud)

但是如何获得当前/活动分支?

Bre*_*ter 21

Branch.IsCurrentRepositoryHead 应该做的伎俩.

Repository.Head如果你不想遍历分支,我想也会做同样的事情......