-
Notifications
You must be signed in to change notification settings - Fork 889
git push
David Robinson edited this page Mar 22, 2020
·
8 revisions
$ git push
using (var repo = new Repository("path/to/your/repo"))
{
LibGit2Sharp.PushOptions options = new LibGit2Sharp.PushOptions();
options.CredentialsProvider = new CredentialsHandler(
(url, usernameFromUrl, types) =>
new UsernamePasswordCredentials()
{
Username = USERNAME,
Password = PASSWORD
});
repo.Network.Push(repo.Branches[BRANCHNAME], options);
}
Another variant, using Remote to push to the origin:
using (var repo = new Repository("path/to/your/repo"))
{
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);
}