如何使用libgit2sharp创建跟踪远程分支的本地分支? git等价物是:
git branch --track development origin/development
答案 0 :(得分:4)
以下代码应该这样做,假设本地development
分支尚不存在。
const string testBranchName = "development";
const string trackedBranchName = "origin/development";
using (var repo = new Repository(path))
{
// Retrieve remote tracking branch
Branch trackedBranch = repo.Branches[trackedBranchName];
Debug.Assert(trackedBranch.IsRemote == true);
// Create local branch pointing at the same Commit
Branch branch = repo.CreateBranch(testBranchName, trackedBranch.Tip);
repo.Branches.Update(branch,
b => b.TrackedBranch = trackedBranch.CanonicalName);
}
注意: BranchFixture.cs 套件包含CanSetTrackedBranch
测试,该测试应为您提供进一步的使用详情。