【问题标题】:libgit2sharp branch not found on freshly cloned repo在新克隆的 repo 上找不到 libgit2sharp 分支
【发布时间】:2015-09-25 21:14:49
【问题描述】:

libgit2sharp 0.21.0.176 Windows Server 2008 上的 C#

我需要获取对特定分支的引用。

在我的 Windows 机器上,我从 GitHub 上的远程源重新 git clone 本地存储库。

接下来我执行libgit2sharp 代码:

var localRepo = new Repository({local-path},RepositoryOptions);
var remote = localRepo.Network.Remotes.Add("origin", {remote-repo-uri);
localRepo.Network.Fetch(remote, FetchOptions, Signature, "performing fetch");
var branch = localRepo.Branches[{branch-name}];

但该分支不存在于集合中,即使它存在于 GitHub 上的远程源上。

【问题讨论】:

    标签: git git-branch git-clone libgit2sharp repo


    【解决方案1】:

    与 git 类似,克隆时仅将默认分支(或在 CloneOptions.BranchName 中指定的分支)创建为本地头。

    获取其他分支,但仅作为远程跟踪分支。

    两种选择:

    • 鉴于您的遥控器名为“origin”,您可以通过localRepo.Branches["origin/{branch-name}"];访问这些远程跟踪分支
    • 您创建一个本地分支并将其配置为跟踪其远程副本。有关如何执行此操作的示例,请参阅 BranchFixture.CanSetUpstreamBranch() 测试。

    【讨论】:

      猜你喜欢
      • 2014-03-17
      • 2017-09-16
      • 1970-01-01
      • 2015-12-11
      • 2020-10-09
      • 2020-07-22
      • 2013-08-07
      • 2021-10-15
      • 2011-07-30
      相关资源
      最近更新 更多