Git# and .NET
What is GitSharp?
GitSharp is an implementation of Git for the .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.
GitSharp provides a fluent syntax for interacting with Git repositories. It also provides a git.exe implemented in C# but it isn't 100% complete. Once the git.exe is complete hopefully it can become a full replacement for msysgit.
Small Console Example
This small C# example shows how you can use the GitSharp API to list all the commits and the data regarding that commit.
var repo = new Repository("C:\\MyGitRepo");
var commits = repo.Head.CurrentCommit.Ancestors;
foreach (var commit in commits)
{
Console.WriteLine("----------");
Console.WriteLine("Commited by: {0} <{1}>",
commit.Committer.Name,
commit.Committer.EmailAddress
);
Console.WriteLine("Commited on: {0}",
commit.CommitDate
);
Console.WriteLine("Commit message: {0}",
commit.Message
);
Console.WriteLine("----------");
}
You should replace "C:\\MyGitRepo&guot; with the path of an actual repository on your system. The output will be a list of commits made to the repository including the person who commited, their email address, the date of the commit, and the commit message.
API includes the following...
- Repository operations
- Commit operations
- Tree and Leaf operations
- Blob operations
- Branch operations
- Ref operations
- Initialising repositories
- Cloning repositories
GitWebSharp
I have plans for an open source project called GitWebSharp which will be a web frontend for Git repositories written using the ASP.NET MVC framework. The project page can be found on GitHub at http://github.com/tombell/GitWebSharp.