3

下面的代码将 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);
    }
}

我想在将其合并到本地 Git 之前获取一个新分支。无论如何,它会引发An error was raised by libgit2. Category = Net (Error). Request failed with status code: 401异常。

如何解决这个问题?

4

1 回答 1

3

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

repo.Fetch("origin", new FetchOptions { Credentials = credential});
于 2014-02-25T11:42:53.910 回答