You can use this lib https://github.com/libgit2/libgit2sharp
wiki of libgit2ssharp: https://github.com/libgit2/libgit2sharp/wiki
I have use it in the past and it's pretty good.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Git Functionalities using c# Console Application - Commit new file / edit existing file to git
How to read from git repository.
Commit a new file to git repository.
Commit a existing file with changes to git repository.
Can any one provide necessary c# code using Microsoft.TeamFoundation.SourceControl.WebApi .
You can use this lib https://github.com/libgit2/libgit2sharp
wiki of libgit2ssharp: https://github.com/libgit2/libgit2sharp/wiki
I have use it in the past and it's pretty good.
Hi rmaurodev,
This contains only related to committing from local repository to git repository,
I was looking for writing directly to git repository.
while trying
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);
}
not able to identify what value to provide on "origin" and @"refs/heads/master"
The api would use the same steps
Stage the file to local repo
https://github.com/libgit2/libgit2sharp/wiki/git-add
Commit the file
https://github.com/libgit2/libgit2sharp/wiki/git-commit
Push to remote ( your code)
You may need to pull first to get your local in sync
You also need to know the branch names to create the proper refs
https://git-scm.com/book/en/v2/Git-Internals-Git-References
In the past the main branch was often named “master” but this is not common anymore.