下面的代码将 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/