c# - 如何使用 LibGit2Sharp 从 Git 获取更改?

标签 c# .net git version-control libgit2sharp

下面的代码将 Git url 克隆到测试目录。

var url = @"http://abc-555.com/team/project-555.git";
var path = @"E:\temp_555";

var credential =  new Credentials() { Username = "a8888", Password="88888888"};
var clonePath = Repository.Clone(url, path, credentials: credential);

using (var repo = new Repository(clonePath))
{
    foreach (var branch in repo.Branches)
    {
        Console.WriteLine(branch.Name);
    }

    // somebody creates a new branch here, so I want to fetch it.
    repo.Fetch("origin");

    foreach (var branch in repo.Branches)
    {
        Console.WriteLine(branch.Name);
    }
}

我想在 merge 到本地 Git 之前获取一个新分支。无论如何,它抛出 An error was raised by libgit2.类别 = 净值(错误)。请求失败,状态代码:401 异常。

如何解决这个问题?

最佳答案

您可以通过 FetchOptions 指定要使用的凭证 实例作为 Fetch 调用的最后一个参数。

repo.Fetch("origin", new FetchOptions { Credentials = credential});

关于c# - 如何使用 LibGit2Sharp 从 Git 获取更改?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22012323/

相关文章:

c# - 无法加载 DLL ‘ABCpdf9-32.dll’。找不到指定的模块(HRESULT 异常 : 0x8007007E)

git - 无法 git pull ubuntu [无法创建符号链接(symbolic link)文件名太长]

git - 无法一开始就使用 git@github.com 克隆存储库?

c# - HttpContext 在任务中变为 NULL

c# - 我的静态 DAL 中的 MySQL 线程问题

c# - 如何创建具有相同签名但不同泛型类型的扩展方法?

c# - 通过两个代理的 HttpWebRequest

eclipse - EGit 2.3 新增--no-ff 选项,如何使用?

c# - 具有相同签名的成员已被声明

asp.net - 如何在Visual Studio 2019中创建ASP.NET网站?