Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

git

c#

.net

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.

like image 271
cnd Avatar asked Mar 25 '11 12:03

cnd


People also ask

How does Git integrate with Visual Studio?

Open an existing Git repository. If your code is already on your machine, you can open it by using File > Open > Project/Solution (or Folder) and Visual Studio automatically detects if it has an initialized Git repository.

How do I open the Git console in Visual Studio?

From the Visual Studio View menu, open Team Explorer or use the Ctrl+, Ctrl+M hotkey. Team Explorer and the Git command-line work great together.

What is Git in asp net?

Git is a free and open source distributed. version control system designed to handle. everything from small to very large projects. with speed and efficiency. Created by Linux creator, Linus Torvalds.


3 Answers

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.

like image 111
Pok Avatar answered Oct 02 '22 08:10

Pok


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.

like image 35
Kenny Evitt Avatar answered Oct 02 '22 10:10

Kenny Evitt


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...

like image 28
Daniel A. White Avatar answered Oct 02 '22 10:10

Daniel A. White