Git server on Windows

DVCS

Distributed version control systems gained a lot of attention over the last few years. There are many hosting providers that offer free DVCS space on the web. But there are situations that you want to run your own private DVCS server and do not want use a publicly and open DVCS like Gitorious, Github or BitBucket. Of-course you can always buy a commercial offering for a private DVCS solution.

The nice thing about a DVCS is that there is not one version, there are multiple ‘versions’ of a source tree. But at some point you do want a central location to store your (releases) sources. In this article I will explain how to setup a Git server on a Windows machine using Apache to server Git request over HTTP.

If you want to know more, Atlassian has an excellent presentation on DVCS, recorded at the Atlassian Summit last June. And Linus Torvalds talk on Git is worth your time: http://www.youtube.com/watch?v=4XpnKHJAok8

msysgit

You will need to install msysgit, I used version msysGit-fullinstall-1.7.6-preview20110708.exe. On my machine I installed msysgit to D:/dev/msysgit

Repositories

Create a directory that contains your Git repositories, for example: D:/dev/repo/git. To get you started, go to the directory and create an empty Git repository.

cd D:/dev/repo/git
git init --bare Test.git

Apache configuration

In this tutorial I use Apache 2.2.19. You need to setup git-http-backend.exe in order to serve Git through Apache. First copy ..\msysgit\mingw\bin\libiconv-2.dll to ..\msysgit\libexec\git-core or else you will get a 500 error from Apache. To test if your setup works run ..\msysgit\libexec\git-core\git-http-backend.exe

Add the following to your Apache conf\httpd.conf:

SetEnv GIT_PROJECT_ROOT D:/dev/repo/git
SetEnv GIT_HTTP_EXPORT_ALL
ScriptAliasMatch \
        "(?x)^/(.*/(HEAD | \
                        info/refs | \
                        objects/(info/[Apache Git server on Windows^/]+ | \
                                 [0-9a-f]{2}/[0-9a-f]{38} | \
                                 pack/pack-[0-9a-f]{40}\.(pack|idx)) | \
                        git-(upload|receive)-pack))$" \
                        "D:/dev/msysgit/libexec/git-core/git-http-backend.exe/$1"

I also made the Apache DocumentRoot point to my Git repos:

DocumentRoot "D:/dev/repo/git"

<Directory "D:/dev/repo/git">
    Options Indexes FollowSymLinks
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>

The result:

Using the repo

You can create a local copy of this git repo using the clone command.

git clone http://localhost/Test.git

Warning

Make sure that you setup authentication if you do not want your sources to become publicly available. This can be done using the regular Apache authentication modules.

Links

Many thanks to: http://www.jeremyskinner.co.uk/2010/07/31/hosting-a-git-server-under-apache-on-windows/

9 Responses to “Git server on Windows”

  1. sekar says:

    hi,

    i would like to know the steps to install and configure gitweb on windows using apache.any one can help to me

    Regards,
    sekar

  2. http://www.deskapahendri.com/2011/02/28/jasa-setting-mikrotik-dan-proxy-super-ngebut-24-jam/ says:

    Jasa Setting Mikrotik dan Proxy Cepat

  3. Yaya says:

    Hi,
    I’can’t get the thing to run. I’m stuck with a HTTP:403 error when trying to clone Test.git. I’ve made sure that the RWX permissions are granted for every body and the apache server is runing correctly. here are the commands:

    D:\home\dev\Projects>git clone http://localhost:8086/Test.git
    Cloning into ‘Test’…
    error: The requested URL returned error: 403 while accessing http://localhost:80
    86/Test.git/info/refs
    fatal: HTTP request failed

    Thanx for your time.

    • soudmaijer says:

      Did you init the Git repo with the –bare option? If not, this will also result in a 403.

      Another easy way of hosting a git repo on windows is using SCM manager.

      HTH.

      Stephan

  4. Yaya says:

    Hi,

    I did init the repo with -bare but nothing has changed.
    Thanks for your response, i’ll check give a look to SCM manager.

    Thanks again.
    Yaya.

  5. Bobo says:

    I have found recently GitStack ( http://gitstack.com ) which does the same as you tutorial (which is great). It is based on apache and msysgit.

  6. AA says:

    D:\Git>git clone http://localhost/Test.git
    Cloning into ‘Test’…
    fatal: repository ‘http://localhost/Test.git/’ not found

    help me please

    • Josh Gough says:

      This is the same thing that is happening to me. I might just use Linux soon instead of messing with this.