Virtual Git Server .NET

A git server for your own data, in .NET.

Virtual Git Server is a C# library that lets users clone, fetch and push with the regular git client, while every request is answered from your data model - a database, a blob store, an API. No repository on disk, no git binary on the server.

$ dotnet add package GenHTTP.Modules.Git
  • Pure C#, no git binary
  • Smart HTTP, protocol v2
  • Clone, fetch and push
  • GenHTTP and ASP.NET Core
  • MIT licensed

Program.cs

var git = GitServer.Create()
                   .Repository(new DocumentRepository(store));

await Host.Create()
          .Handler(git)
          .RunAsync();

Shell

$ git clone http://localhost:8080/ documents
Cloning into 'documents'...
$ git commit -am "Update the pricing page"
$ git push
remote: Saved as version 13
To http://localhost:8080/
   3f2a1c9..8d0e4b2  main -> main

Git is the interface. Your data stays the source of truth.

Developers, CI pipelines and coding agents already speak git. If your application manages versioned content, offering it over git replaces custom sync tools and upload forms - without running a second system next to your own.

Hosting real repositories

  • Two sources of truth, kept in sync by jobs and hooks
  • Repositories on disk, to be stored, backed up and migrated
  • A git installation on the server, called as a process
  • Permissions and validation bolted on in front of git-http-backend

A virtual repository

  • One source of truth: branches, commits and files come from your model
  • Commits stored as a few hundred bytes next to your records
  • Files loaded from your storage only when a client needs them
  • Pushes handed to you parsed and verified - you decide what to accept

Implement three methods. Add a fourth to accept pushes.

The server speaks the git protocol; your code describes the repository. Whenever a client needs something, the server asks your implementation and converts the answer into what git expects.

  1. GetReferencesAsync()

    Branches and tags

    Whatever your model provides: a branch per draft, a tag per version, and the branch a clone checks out.

  2. GetCommitAsync(id)

    Commits

    Created once when your data changes and restored from their stored bytes, so the history never changes under a client.

  3. GetTreeAsync(commit)

    Files

    A flat list of paths with text, bytes or a loader - directories, blobs and object ids are computed for you.

  4. PushAsync(push)

    Pushes

    Every update with its commits and files. Accept it, reject it with a reason, report progress as remote: lines.

  • Answers only what git asks for.An incremental fetch reads the files of the new commits and the one they build on - nothing else. git ls-remote reads no files at all.
  • Verified before you see it.Packs, deltas and checksums are checked, unsafe paths and unsupported objects rejected, and every update must be based on the current state.
  • Deleted history is fine.Keep only the newest versions: the repository is served as shallow, and existing clones keep fetching as before.

DocumentRepository.cs

public sealed class DocumentRepository(Store store) : IWritableGitRepository
{

    // one branch with the newest version, a tag per version
    public ValueTask<GitReferences> GetReferencesAsync() => ...;

    // a commit by its id, as stored when the version was saved
    public ValueTask<GitCommit?> GetCommitAsync(GitObjectId id) => ...;

    // the files of a commit, loaded lazily if needed
    public ValueTask<GitTree> GetTreeAsync(GitCommit commit) => ...;

    // accept or reject what a client pushed
    public async ValueTask PushAsync(GitPush push)
    {
        foreach (var update in push.Updates)
        {
            var version = await store.SaveAsync(update.Revisions);

            await push.MessageAsync($"Saved as version {version.Number}");

            update.Accept();
        }
    }

}

What people build with it

Any application that keeps versions of something can let its users work on them with git.

Platforms for coding agents

Let Claude Code, Codex or Cursor clone an app, change it and push it back as the next version. GenHTTP Lambda serves every app as a repository this way.

Content and documents

Expose the pages, templates or documents of a CMS as files, with a tag per published version and a branch per draft.

Configuration as code

Offer settings, rules or workflows stored in your database as a repository that CI pipelines check out and teams review.

Snippets and low-code apps

Give users of an online editor a way to work locally in their own IDE and push their changes back.

Datasets and exports

Publish snapshots of data as commits, so consumers receive changes with git pull and see exactly what changed.

Tests and tooling

Spin up an in-memory repository in a unit test to exercise code that clones, fetches or pushes, with no git server to install.

The git protocol, implemented from scratch

Tested against the git client with transfer.fsckObjects enabled and verified with git fsck --strict, over protocol v0 and v2.

TransportSmart HTTP, protocol v2 (ls-refs, fetch) and v0/v1 for fetching, v0 for pushing, compressed and chunked requests
FetchingClones, incremental fetches, shallow clones (--depth, --shallow-since, --shallow-exclude, --deepen)
PushingCreating, updating and deleting branches and tags, deltas, push options, remote: messages, pushes from shallow clones
HistoryTruncated histories (deleted old versions) are served as shallow repositories
FilesRegular files, executables and symbolic links, loaded on demand, with a content cache
HostingOne or many repositories, resolved per request, on any GenHTTP engine or in ASP.NET Core, with authentication and size limits

Not supported: SSH, the dumb HTTP protocol, SHA-256 repositories, partial clones (--filter), annotated tags and submodules. See protocol support for every detail.

Already on ASP.NET Core?

The repository is a regular GenHTTP handler. One adapter package maps it to a path of your WebApplication, next to your controllers, Razor pages and minimal APIs - every other request passes through untouched.

Program.cs

using GenHTTP.Adapters.AspNetCore;
using GenHTTP.Modules.Git;

var app = WebApplication.CreateBuilder(args).Build();

// git clone https://example.com/repo
app.Map("/repo", GitServer.Create().Repository(repository));

app.MapGet("/", () => "Hello from ASP.NET Core");

await app.RunAsync();

Frequently asked questions

Does the server need git installed?

No. The library implements the git smart HTTP protocol in C#, from parsing and writing packs to deltas and zlib. Nothing is started as a process and nothing is written to disk; git is only needed on the machines of your users.

Does it work with ASP.NET Core?

Yes. With the GenHTTP.Adapters.AspNetCore package, app.Map("/repo", GitServer.Create().Repository(repository)) serves a repository at a path of your WebApplication, next to your controllers, Razor pages and minimal APIs.

Can users push?

Yes. Implement IWritableGitRepository and the server hands you every push, parsed and verified, as reference updates with their commits and files. You accept or reject each update, can send remote: messages to the client and read push options such as git push -o deploy.

How is it different from git-http-backend or LibGit2Sharp?

git-http-backend and the libraries built on it or on libgit2 serve repositories that exist on disk, so your application has to keep a real repository in sync with its data. Virtual Git Server has no repository: it asks your code for branches, commits and files whenever a client needs them, so your data model stays the single source of truth.

Which git features are supported?

Smart HTTP with protocol v2 and v0/v1 for fetching and v0 for pushing; clones, incremental fetches and shallow clones; creating, updating and deleting branches and lightweight tags; regular files, executables and symbolic links. Not supported are SSH, the dumb HTTP protocol, SHA-256 repositories, partial clones, annotated tags and submodules.

Which .NET versions are supported?

The NuGet package GenHTTP.Modules.Git targets .NET 10 and .NET 11 and runs on every GenHTTP engine (internal, Kestrel and ioxide) or inside an ASP.NET Core application.

What does it cost?

Nothing. Virtual Git Server is open source under the MIT license.

Serve your first repository in five minutes.

$ dotnet add package GenHTTP.Modules.Git