Hosting a Git server under IIS7 on Windows

Update: Please be aware that an alternative (and probably more stable) the approach for hosting a git http server under windows is to use Apache which I blogged about here.

Traditionally Git requires the use of SSH if you want to host read/write repositories on a server. While this is certainly possible to do on Windows by running OpenSSH under Cygwin, it isn’t a particularly simple process and does require some familiarity with unix/linux.

However, with the smart HTTP support introduced with with Git 1.6.6 it is now possible to push to git repositories over HTTP. Although the default implementation of the smart http protocol requires the use of apache, there are other implementations available. For example, Grack is a ruby-based implementation using the Rack framework and git_http_backend.py implements similar functionality in Python.

I decided to have a go at putting together a native .NET implementation of git-http-backend using ASP.NET MVC and the excellent GitSharp library. The result is available on GitHub in the imaginatively titled git-dot-aspx (GitAspx) project.

To get started, you’ll need to download the source and compile the project download the binaries from the github project page.

Once compiled, create a new web site in IIS and point it at the directory containing the application. Be sure to select the ASP.NET v4 Application Pool.

image

Next, you’ll need to edit the application’s web.config so GitAspx knows where to look for your repositories. This is done by setting the “RepositoriesDirectory” app setting:

<appsettings>
    <add value="C:Repositories" key="RepositoriesDirectory" />
</appsettings>

Once configured, browsing to the application will display a list of projects. Clicking on a project shows the clone URL:

Capture

You can now clone, pull and push from this URL:

git clone http://localhost:8080/FluentValidation
echo foo > foo.txt
git add -A
git commit -m "Committing"
git push origin master

It’s probably a good idea to put some authentication in place (eg basic authentication over SSL) so not just everyone can push to your repositories! You can also allow/deny access to specific projects using the standard ASP.NET URL authorization mechanism.

At present, this is only an implementation of the “smart” protocol (which allows both push/pull), but I’m also planning on adding support for the “dumb” protocol to be backwards compatible with older clients.  Update 19 Oct 2010: Support for the dumb protocol is available as of the 0.3 release.

Written on June 25, 2010