Is there some way to work with git using .NET application?

C#.NetGit

C# Problem Overview


How can I pull (maybe push too) some folder from GitHub?

I mean I need API for .NET to access within C#, not GUI for git.

C# Solutions


Solution 1 - C#

What I have done is however to write a simple class libray to call git commands by running child process.

First, create a ProcessStartInfo for some configuration.

ProcessStartInfo gitInfo = new ProcessStartInfo();
gitInfo.CreateNoWindow = true;
gitInfo.RedirectStandardError = true;
gitInfo.RedirectStandardOutput = true;
gitInfo.FileName = YOUR_GIT_INSTALLED_DIRECTORY + @"\bin\git.exe";

Then create a Process to actually run the command.

Process gitProcess = new Process();
gitInfo.Arguments = YOUR_GIT_COMMAND; // such as "fetch orign"
gitInfo.WorkingDirectory = YOUR_GIT_REPOSITORY_PATH;

gitProcess.StartInfo = gitInfo;
gitProcess.Start();

string stderr_str = gitProcess.StandardError.ReadToEnd();  // pick up STDERR
string stdout_str = gitProcess.StandardOutput.ReadToEnd(); // pick up STDOUT

gitProcess.WaitForExit();
gitProcess.Close();

It is then up to you to call whatever command now.

Solution 2 - C#

As James Manning mentioned in a comment in the currently accepted answer, the library libgit2sharp is an actively supported project providing a .NET API for Git.

Solution 3 - C#

I just found this: http://www.eqqon.com/index.php/GitSharp > GitSharp is an implementation of Git for the Dot.Net Framework and Mono. It is aimed to be fully compatible to the original Git and shall be a light weight library for cool applications that are based on Git as their object database or are reading or manipulating repositories in some way...

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestioncndView Question on Stackoverflow
Solution 1 - C#PokView Answer on Stackoverflow
Solution 2 - C#Kenny EvittView Answer on Stackoverflow
Solution 3 - C#Daniel A. WhiteView Answer on Stackoverflow