libgit2 / libgit2sharp

Git + .NET = ❤
http://libgit2.github.com
MIT License
3.13k stars 879 forks source link

Push my commit #1993

Closed AndreZila01 closed 1 year ago

AndreZila01 commented 1 year ago

I try make a commit and push in same function but, the program cannot do a push. I see the commit in github desktop, but program doesn't push the commit and return this errors: image

My code at the moment is this:

string directory = @"REPOSITORY";
    using (var repo = new Repository(directory))
    {
        // Create the committer's signature and commit
        LibGit2Sharp.Signature author = new LibGit2Sharp.Signature("USERNAME", "EMAIL", DateTime.Now);
        LibGit2Sharp.Signature committer = author;

        // Commit to the repository
        Commit commit = repo.Commit("MESSAGE COMMIT", author, committer);
    }

    using (var repo = new Repository(directory))
    {
        Remote remote = repo.Network.Remotes["origin"];
        var options = new PushOptions();
        options.CredentialsProvider = (_url, _user, _cred) =>
            new UsernamePasswordCredentials { Username = "USERNAME", Password = "PASSWORD" };
        repo.Network.Push(remote, @"refs/heads/master", options);
    }
ethomson commented 1 year ago

Your username and password are not being accepted by the remote.

AndreZila01 commented 1 year ago

Ehn, ok @ethomson and how i make to repository will accepted my user? I added my account to "Contributors" on repository and do pushed on git cmd and worked, when i try do on program returned the same error.

ethomson commented 1 year ago

What hosting provider? Most providers don't let you use http basic with your username and password and instead require you to create an auth token. Use that as your password.

AndreZila01 commented 1 year ago

OHHHH ok thanks. Now i understand ethomson. Thanks for helped!