【问题标题】:How to set a remote using libgit2sharp?如何使用 libgit2sharp 设置遥控器?
【发布时间】:2014-10-26 09:19:11
【问题描述】:

我正在尝试做这样的事情:

var origin = repository.Network.Remotes["origin"];
repository.Head.Remote = origin;

唯一的问题是“远程”是只读的(我使用的是 0.14.1.0)。如何为 HEAD 设置默认遥控器?

【问题讨论】:

    标签: push pull libgit2sharp


    【解决方案1】:

    虽然我强烈建议您更新您的版本,但下面的代码应该可以帮助您入门并在 v0.14.1 中工作。

    Remote remote = repo.Network.Remotes["origin"];
    
    Branch branch = repo.Head;
    Branch updatedBranch = repo.Branches.Update(branch,
        b => b.Remote = remote.Name,
        b => b.UpstreamBranch = branch.CanonicalName);
    

    另请参阅此 SO answer,它提供了有关分支跟踪配置的一些说明。

    【讨论】:

      猜你喜欢
      • 2014-02-27
      • 2019-11-27
      • 2016-02-06
      • 1970-01-01
      • 2014-10-28
      • 2011-11-25
      • 2017-09-20
      • 2014-08-11
      • 2017-11-22
      相关资源
      最近更新 更多