Setting up a Git Server on Windows Server 2008 R2 (using msysgit and WinSSHD) [Update]

This is a follow-up post from this one. It is inspired by a comment from Dan Kendall. So thanks Dan.

In the portable version of msysgit the git-upload-pack.exe and the git-receive-pack.exe files are also located in the bin/ folder. This allows us to shrink the configuration down and even skip all configuration steps on the client.

The basic setup is the same as in the original post.

The server configuration is a bit different though.

1. Download the portable version of msysgit and extract it to C:\Git.

2. Add C:\Git\bin to the PATH variable.
(If you don’t want to use the portable msysgit for whatever reason, you also have to add C:\Git\libexec\git-core to the PATH)

3. Create a new file in C:\Git\bin and just insert


Save it as shell script (.sh). E.g. “”.
This basically executes the all parameters that are passed and solves the quotes-problem that is mentioned in the original post. There are surely other approaches to solve this issue and if you find a better one please do not hesitate to post a comment.

4. In WinSSHD open the advanced settings and edit the user account(s) you have set up before. Scroll down a bit and uncheck “Use group default exec request prefix”. Then change the “Exec request prefix” to

cmd.exe /c sh 

Be sure to add a space at the end.

5. Done. You can connect to the server with your Git client.

git clone|push|pull|etc. ssh://username@server/path/to/myrepo 

15 Responses to “Setting up a Git Server on Windows Server 2008 R2 (using msysgit and WinSSHD) [Update]”

  1. Setting up a Git Server on Windows Server 2008 R2 (using msysgit and WinSSHD) « Holyhoehle's Blog Says:

    […] Setting up a Git Server on Windows Server 2008 R2 (using msysgit and WinSSHD) [Update] […]

  2. Git Server with sshd on windows Server | jerry-yang work's logs Says:

    […] 網路芳鄰的方式(網路磁碟)來架設Git Server。我來發現了一篇使用winsshd來架設Git Server的教學。 1. 現在我們開始來架設Git […]

  3. TeamWahoo Says:

    Steffen, what tool are you using for your code samples?

  4. Git Server Windows - Gitstack Says:


    we’re actually working on a new simple solution to install a git server under Windows. The solution’s name is GitStack (web site :


  5. aleksandrmakov Says:

    Thanks for sharing very good info out here.

    The only problem I have is that “sh” command could not be recognized. Should this guide presume availability of cygwin on the system?

  6. aleksandrmakov Says:

    Thanks for sharing! Very easy and flexible setup!!

  7. 9d8c21ab6885c241b9ca3cf3cdf03b94 Says:

    The setup you described is very helpfull. But it lacks some security features which can be easily added.
    I wont describe settings besides used for Git, as they are up to person to define.
    The vulnerability I found is ability to execute any command with ssh request, not only git-specific ones. I’we executed “rm /path/to/some.thing” sucessfully, and I see no reason why more destructive commands cannot be executed.
    To prevent it I’we made some basic input checks.
    Besides my way of using Git allows to keep PATH cleaner, as there is no need to add Git directory to it.
    I use WinSSHD 5.26, and Git for Windows 1.7.10 installed as “Git bash only”, wihtout path changes
    For simpicity, Git is under “c:\Git”, repos are under “c:\repos\git_repos”
    In WinSSHD:
    Initial terminal shell directory = “c:\Git\bin”, to make git.exe and sh.exe avaiable
    Exec request prefix = “c:\Git\bin\git-request-handler.bat “, batch file to work with input, with space
    Basic input check is done in git-request-handler.bat

    @setlocal enableextensions enabledelayedexpansion
    @set str1=%1
    @if not x%str1:git=%==x%str1% (cmd.exe /c sh.exe %1 /c/repos/git_repos%2) else (echo Denied)

    Parameters %1 and %2 are input parameters for calls. With “git clone user@host/repo” %1 will be “git-upload-pack” and %2 will be “/repo”
    The wierd string check executes command only if it has substring “git” in it, i’ve googled this syntaxis
    If there is no “git” in called command script will echo Denied and exit, terminating session
    Another usefull thing is that called repository can be perepended with local directory, shortening requests
    On positive check SH is called to execute script, descendatnt of, extended a bit, with parameters representing command and modified path is located in c:\Git\bin

    export PATH=/c/Git/bin:/c/Git/libexec/git-core

    This defines PATH, further restricting avaiable commands, and allowing calls to both “git” and “git-*-pack” form SH
    This setup can be improved further, by checking repo folder, or another way of handling substring check

  8. DB Says:

    Thank you, Steffen. The “” tip is great. It pulled me out of a very frustrating week 🙂 Your help is much appreciated!

  9. axpasser Says:

    Thank you!!! this tutorial really help me a lot, now I can finally “git clone” without the frustrating error 🙂

  10. Jason Goemaat Says:

    Thanks aleksandrmakov, I couldn’t figure out how to use any directory but the git directory for repositories. I just made my file this (for git installed in “C:\G” and my repositories in “C:\git\.repositories”:

    export PATH=/c/g/bin:/c/g/libexec/git-core
    $1 /c/git/.repositories$2

  11. nexus6 Says:

    in winsshd set terminal shell to c:\….\Git\bin\sh.exe .. so u can access your remote folder structure like so ssh://user@server/path/to/repo.git

  12. Moni Says:

    Hi Guys,
    I followed the same steps but I stumble upon the following error:
    C:\Git\bin\ line 1: C:/Git/libexec/git-core/git-receive-pack.exe /C:/wamp/www/TestProject: No such file or directory
    When i run git push –exec ‘sh C:\Git\bin\’ ssh://myuser@server/C:/wamp/www/TestProject

    Now i know what the problem is but I cannot figure out the solution. The problem here is that /C:/wamp/www/TestProject is not valid path, instead C:/wamp/www/TestProject is. So how do I change my push command so that the path is the correct one?

    Thanks guys

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: