How to fetch change from Git using LibGit2Sharp?

ⅰ亾dé卋堺 提交于 2019-12-23 17:26:40

问题


The code below clone a Git url to a test directory.

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);
    }
}

I want to fetch a new branch before merging it to local Git. Anyway, it throws An error was raised by libgit2. Category = Net (Error). Request failed with status code: 401 exception.

How to fix this?


回答1:


You can specifiy the credentials to be used through a FetchOptions instance as the last parameter of the Fetch call.

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


来源:https://stackoverflow.com/questions/22012323/how-to-fetch-change-from-git-using-libgit2sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!