2014-03-26 139 views

回答

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測試,應爲您提供進一步的使用細節。

相關問題