GitDotNet.Microsoft.Extensions.DependencyInjection
0.1.17-alpha
See the version list below for details.
dotnet add package GitDotNet.Microsoft.Extensions.DependencyInjection --version 0.1.17-alpha
NuGet\Install-Package GitDotNet.Microsoft.Extensions.DependencyInjection -Version 0.1.17-alpha
<PackageReference Include="GitDotNet.Microsoft.Extensions.DependencyInjection" Version="0.1.17-alpha" />
<PackageVersion Include="GitDotNet.Microsoft.Extensions.DependencyInjection" Version="0.1.17-alpha" />
<PackageReference Include="GitDotNet.Microsoft.Extensions.DependencyInjection" />
paket add GitDotNet.Microsoft.Extensions.DependencyInjection --version 0.1.17-alpha
#r "nuget: GitDotNet.Microsoft.Extensions.DependencyInjection, 0.1.17-alpha"
#addin nuget:?package=GitDotNet.Microsoft.Extensions.DependencyInjection&version=0.1.17-alpha&prerelease
#tool nuget:?package=GitDotNet.Microsoft.Extensions.DependencyInjection&version=0.1.17-alpha&prerelease
GitDotNet is a .NET library designed to read Git repositories in a fully native .NET environment. It is optimized for minimal memory footprint and efficient data retrieval from repositories.
It also supports writing, but it doesn't write itself: it uses git fast-import to write objects and refs to the repository. This guarantees best writing performance, safe git data writing, and avoid having to reinvent the wheel (object compression...).
Features
- Supports .NET 8 and 9. Note that .NET 9 is highly recommended because it uses zlib-ng which is much faster.
- Read and parse Git objects (commits, trees, blobs, tags, index...) natively in .NET.
- Write using the git fast-import feature for high efficiency and reliability.
- Use of memory-mapped files for high-performance .git repository data reading.
- Asynchronous methods for efficient data retrieval.
- Minimal memory footprint with lazy loading of data and usage of data streaming.
- Comparison of git commits and trees, along with renaming detection and git patch creation.
<details> <summary>Detailed status...</summary> As per high-level git features, the following is the current status of the project:
-
clone:GitConnection.Create(path, isBare)
-
fetch:connection.Branches["main"].Fetch()
- blame
- push
- reset
- status
-
commit/trees diff(including renaming detection):connection.CompareAsync("HEAD~10", "HEAD")
- merge
- blobs
- trees
- commits
- rebase
-
commitawait connection.CommitAsync("main", c => c.AddOrUpdate("test.txt", Encoding.UTF8.GetBytes("foo")), connection.CreateCommit(...))
- worktree checkout
- worktree stream
-
read history:connection.GetLogAsync("HEAD~1", LogOptions.Default with { ... })
,await (foreach commint in connection.Branches["fix/bug"])
-
.NET native reading of objects:connection.GetAsync<BlobEntry>("1aad9b571c0b84031191ab76e06fae4ba1f981bc")
-
.NET native reading of:.git/index
connection.Index.GetEntriesAsync()
-
writing of objects(uses fast-import):connection.CommitAsync("main", c => c.AddOrUpdate("test.txt", Encoding.UTF8.GetBytes("foo")), connection.CreateCommit(...))
- writing of
.git/index
-
reading of git configuration:connection.Config.GetProperty("user", "email")
- writing of git configuration
Note that the main purpose of DotNetGit is to provide high speed reading. Writing can be done through commands. </details>
Installation
To install GitDotNet, add the GitDotNet
or GitDotNet.Microsoft.Extensions.DependencyInjection
NuGet package to your project.
Usage
- Add GitDotNet dependencies to your
IServiceCollection
using theAddGitDotNet
extension method. This will injectConnectionProvider
and other required services. - Use the
Objects.GetAsync
method to retrieve Git objects by their hash. - Use the provided methods to parse and display the content of commits, trees, blobs, and tags.
using Microsoft.Extensions.DependencyInjection;
using GitDotNet;
var services = new ServiceCollection()
.AddMemoryCache(o => o.SizeLimit = 10_000_000) // Each entry size is always 1
.AddGitDotNet();
var provider = services.BuildServiceProvider().GetRequiredService<GitConnectionProvider>();
using var connection = await provider("path/to/repo");
var commit = await connection.Branches["main"].Tip;
Console.WriteLine($"Commit Message: {commit.Message}");
var tree = await commit.GetTreeAsync();
Benchmarks
GitDotNet vs. LibGit2Sharp: reading random blobs of size from 1kB to 3kB
Method | Runtime | Mean | Error | StdDev | Ratio | RatioSD | Gen0 | Gen1 | Gen2 | Allocated | Alloc Ratio |
---|---|---|---|---|---|---|---|---|---|---|---|
GitDotNet | .NET 9.0 | 266.5 ns | 5.21 ns | 6.95 ns | 1.00 | 0.04 | 0.0243 | - | - | 464 B | 1.00 |
GitDotNet | .NET 8.0 | 322.1 ns | 4.07 ns | 3.61 ns | 1.21 | 0.03 | 0.0243 | - | - | 464 B | 1.00 |
LibGit2Sharp | .NET 9.0 | 23,787.7 ns | 428.43 ns | 379.79 ns | 1.00 | 0.02 | 0.1221 | 0.0305 | - | 2384 B | 1.00 |
GitDotNet vs. native git 2.47.1.windows.1: archiving git repository
Method | Mean | Error | StdDev |
---|---|---|---|
GitDotNet | 6.200 s | 2.676 s | 0.1467 s |
git archive -o result.zip HEAD | 7.357 s | 6.893 s | 0.3778 s |
Contributing
Contributions are welcome! Please open an issue or submit a pull request on GitHub.
License
This project is licensed under the MIT License.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
-
net8.0
- GitDotNet (>= 0.1.17-alpha)
- Microsoft.Extensions.DependencyInjection (>= 9.0.2)
-
net9.0
- GitDotNet (>= 0.1.17-alpha)
- Microsoft.Extensions.DependencyInjection (>= 9.0.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
0.1.35-alpha | 109 | 4/2/2025 |
0.1.17-alpha | 89 | 3/28/2025 |
0.1.6-alpha | 439 | 3/25/2025 |