Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to provide credentials to Fetch() and Pul() methods?

Tags:

libgit2sharp

I'm looking for a nice clean example of how to do a pull using lidgit2sharp. I took the example here which does a fetch, but the reference to Credentials is throwing an exception.

using (var repo = new Repository(workingDir, null))
{
    Remote remote = repo.Network.Remotes.Add("master", repoUrl);
    repo.Network.Fetch(remote, 
    {    
        Credentials credentials = new Credentials
        {
            Username = "username",
            Password = "password"
        }
    });
}

The exception is Cannot create an instance of the abstract class or interface 'LibGit2Sharp.Credentials'

like image 593
theTechGrandma Avatar asked Dec 09 '25 03:12

theTechGrandma


1 Answers

It's telling you in the error: Credentials is an abstract class, interface, whatever.

Try this:

Credentials credentials = new UsernamePasswordCredentials()
{

        Username = "username",
        Password = "password"
}
like image 101
Andy Avatar answered Dec 13 '25 10:12

Andy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!