Pure managed C# implementation for reading from Git repositories.
- Portable and simple
- No dependencies on native code.
- Reading from local Git repositories
- Resolve HEAD and other references to commit SHAs.
- Load all files from any commit's tree.
- Supports both loose objects and pack files.
- Cloning via Git Smart HTTP
- Efficient partial cloning of subdirectories.
- Configurable API for caching git objects to make cloning more efficient.
NuGet: https://www.nuget.org/packages/GitCore/
dotnet add package GitCore
var gitDir = Path.Combine(repoRootDir, ".git");
// Load all files from the current HEAD commit
var filesAtHead = GitCore.LoadFromLocalFiles.LoadTreeContentsFromHead(gitDir);
// Or resolve HEAD and load from a specific commit
var commitSha = GitCore.LoadFromLocalFiles.ResolveHead(gitDir);
var filesAtCommit = GitCore.LoadFromLocalFiles.LoadTreeContentsFromCommit(gitDir, commitSha);
// Resolve any reference (branch, tag, etc.)
var branchSha = GitCore.LoadFromLocalFiles.ResolveReference(gitDir, "refs/heads/main");
// Load the full in-memory object store
var repository = GitCore.LoadFromLocalFiles.LoadRepository(gitDir);var subdirectoryContents =
await GitCore.LoadFromUrl.LoadSubdirectoryContentsFromGitUrlAsync(
gitUrl: "https://github.com/pine-vm/pine.git",
commitSha: "c837c8199f38aab839c40019a50055e16d100c74",
subdirectoryPath: ["guide"]);In the past, I had used LibGit2Sharp to clone Git repositories and read their files. That often works, but the native dependencies of such a solution have caused many problems.
For any app that's hosted in .NET anyway, a pure managed implementation seems the natural way to simplify builds and operations.