title: Setting up Git Server on Windows With git-http-backend.exe
body: <p>I am in the process of setting up a Git server (1.7.2.3) on a WS 2008 machine using Apache and git-http-backend.exe.  I have been following a good tut <a href="http://www.jeremyskinner.co.uk/2010/07/31/hosting-a-git-server-under-apache-on-windows/" rel="noreferrer">here</a>.  I have the GUI working, I can annoymously clone and if I put the following in the config of a repo I can annoymously push:</p>
  
  <pre><code>[http]
   receivepack = true
  </code></pre>
  
  <p>I have added the following to the httpd.conf file:</p>
  
  <pre><code>SetEnv GIT_PROJECT_ROOT C:/GIT/Repositories
  SetEnv GIT_HTTP_EXPORT_ALL
  ScriptAliasMatch \
          "(?x)^/(.*/(HEAD | \
                      info/refs | \
                      objects/(info/[^/]+ | \
                               [0-9a-f]{2}/[0-9a-f]{38} | \
                               pack/pack-[0-9a-f]{40}\.(pack|idx)) | \
                      git-(upload|receive)-pack))$" \
                      "C:/Program Files (x86)/git/libexec/git-core/git-http-backend.exe/$1"
  
  &lt;Directory /&gt;
    Allow from all
  &lt;/Directory&gt;
  
  &lt;LocationMatch "^/git/.*/git-receive-pack$"&gt;
          AuthType Basic
          AuthName "Git Access"
    AuthUserFile C:/GIT/ApacheConfig/users
    AuthGroupFile  C:/GIT/ApacheConfig/groups
          Require group repogeneral        
  &lt;/LocationMatch&gt;
  </code></pre>
  
  <p>When I add the "LocationMatch" I can still clone annoymously or by specifying a name in the URL, git clone <a href="http://jon@myserver.com" rel="noreferrer">http://jon@myserver.com</a></p>
  
  <p>It will prompt for a password and clone.</p>
  
  <p>but when I try to push back to the repo I get the following:</p>
  
  <p>error: Cannot access URL <a href="http://jon@myserver.com/newtestrepo.git/" rel="noreferrer">http://jon@myserver.com/newtestrepo.git/</a>, return code 22
     fatal: git-http-push failed</p>
  
  <p>I have been looking at the <a href="http://www.kernel.org/pub/software/scm/git/docs/git-http-backend.html" rel="noreferrer">http-backend.exe man page</a> for examples but can not get them to work.</p>
  
  <p>here is my groups file, (this is just testing out examples so nothing that would be used in prod):</p>
  
  <pre><code>admin: jon steve admin
  webview: jon steve web
  repogeneral: jon steve
  testrepo: jon admin
  testrepo2: jon steve web
  </code></pre>
  
  <p>here is the users file:</p>
  
  <pre><code>jon:$apr1$kEKVExYx$guIF9oYV8buGhFLZr16XN0
  steve:$apr1$jvgjF9nv$PvWsHH.cSOBN5ymk6NT1B0
  admin:$apr1$vzXgDskN$oszCei3tkHNUgtLj2HkHF/
  web:$apr1$wS0do7hb$VA9tsc9c9LwY5PcjfhdwK0
  </code></pre>
  
  <p>I know the username jon works as if I put the directory requirement on the gui section I can login with the username jon no problem, (points at the same user and group files as the locationmatch does).</p>
  
  <p>I am not sure what configuration I have missed off at this point, (assuming its a configuration issue).</p>
  
  <p>Any advice on getting over this last hurdle would be fantastic.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>I have been playing some more and here is the information I have:</p>
  
  <p>if I clone a repo with:</p>
  
  <pre><code>git clone http://jon@myserver.com/remotetest.git
  </code></pre>
  
  <p>I can get the repository out, but when I try and push back with:</p>
  
  <p>git push origin master</p>
  
  <p>I get asked for my password, I enter it, then it asks for it again, then I get the following error:</p>
  
  <p>C:\temp\remotetest\remotetest>git push origin master
  Password:
  Password:
  error: Cannot access URL <a href="http://jon@myserver.com/remotetest.git/" rel="noreferrer">http://jon@myserver.com/remotetest.git/</a>, return code 22
  fatal: git-http-push failed</p>
  
  <p>In my Apache access.log I get the following:</p>
  
  <pre><code>192.168.1.2 - - [29/Sep/2010:21:58:19 +0100] "GET /remotetest.git/info/refs?service=git-upload-pack HTTP/1.1" 200 38
  192.168.1.2 - - [29/Sep/2010:21:58:51 +0100] "GET /remotetest.git/info/refs?service=git-receive-pack HTTP/1.1" 403 -
  192.168.1.2 - - [29/Sep/2010:21:58:51 +0100] "GET /remotetest.git/info/refs HTTP/1.1" 200 -
  192.168.1.2 - - [29/Sep/2010:21:58:51 +0100] "GET /remotetest.git/HEAD HTTP/1.1" 200 23
  </code></pre>
  
  <p>Interestingly when I clone with the username in the URL it doesn't matter what password I put in, it will still work.  I am assuming this is because I should be able to pull anonymously.  Not sure why it asks for a password at all at that point.</p>
  
  <p>I also see this in the logs error:</p>
  
  <pre><code>[Wed Sep 29 22:33:00 2010] [error] [client 192.168.1.2] client denied by server configuration: C:/Program Files (x86)/Git/libexec/git-core/git-http-backend.exe
  [Wed Sep 29 22:33:00 2010] [error] [client 192.168.1.2] client denied by server configuration: C:/Program Files (x86)/Git/libexec/git-core/git-http-backend.exe
  </code></pre>
  
  <p><strong>EDIT 2</strong></p>
  
  <p>I tried recreating the password file by doing:</p>
  
  <pre><code>htpasswd -c -m C:/git/apacheconfig/users jon
  </code></pre>
  
  <p>but this didn't help.</p>
  
  <p><strong>EDIT 3</strong></p>
  
  <p>the PHP config in httpd.conf where it uses the same users file for basic auth:</p>
  
  <pre><code>&lt;Directory "C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs"&gt;
      AuthName "GitUsers"
      AuthType Basic
      AuthUserFile C:/GIT/ApacheConfig/users
  AuthGroupFile  C:/GIT/ApacheConfig/groups
  
      require group webview
  &lt;/Directory&gt;
  </code></pre>
  
  <p><strong>EDIT 4</strong></p>
  
  <p>OK so I can get to cloning and pushing in annoymous mode happily, but authentication fails for the push.</p>
  
  <pre><code>C:\temp\test2\temp\test&gt;git push origin master
  Password:
  Password:
  error: Cannot access URL http://jon@192.168.10.97:8000/repositories/test.git/, return code 22
  fatal: git-http-push failed
  </code></pre>
  
  <p>I changed the httpd.conf to use the following:</p>
  
  <pre><code>&lt;VirtualHost *:80&gt;
      SetEnv GIT_PROJECT_ROOT "C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs/repositories"
      SetEnv GIT_HTTP_EXPORT_ALL
  
      &lt;Directory "C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs/repositories"&gt;
         Options Indexes FollowSymLinks MultiViews Includes ExecCGI
         AllowOverride None
         Order allow,deny
         Allow from all
      &lt;/Directory&gt;
  
      &lt;LocationMatch "^/repositories/.*/git-receive-pack$"&gt;
          AuthType Basic
          AuthName "Git Access"
          AuthUserFile "C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs/repositories/.htpasswd"
          Require valid-user
      &lt;/LocationMatch&gt;
      ScriptAliasMatch \
              "(?x)^/repositories/(.*/(HEAD | \
                              info/refs | \
                              objects/(info/[^/]+ | \
                                       [0-9a-f]{2}/[0-9a-f]{38} | \
                                       pack/pack-[0-9a-f]{40}\.(pack|idx)) | \
                              git-(upload|receive)-pack))$" \
              "C:/Program Files (x86)/Git/libexec/git-core/git-http-backend/$1"
  
      ErrorLog C:/GIT/error_log
      CustomLog C:/GIT/access_log combined
  &lt;/VirtualHost&gt;
  </code></pre>
  
  <p>Interestingly, when I created a new repo (git init --bare newrepo.git)  It didn't create a info/refs file.  I had to do the "git update-server-info" command to create that.</p>
  
  <p>The Apache Access logs have something interesting that could be a clue:</p>
  
  <pre><code>192.168.10.97 - - [05/Oct/2010:22:48:26 +0100] "GET /repositories/test.git/info/refs?service=git-receive-pack HTTP/1.1" 200 -
  192.168.10.97 - - [05/Oct/2010:22:48:26 +0100] "GET /repositories/test.git/HEAD HTTP/1.1" 200 23
  192.168.10.97 - - [05/Oct/2010:22:48:28 +0100] "PROPFIND /repositories/test.git/ HTTP/1.1" 405 248
  </code></pre>
  
  <p>That is when I was trying to "push" back to the repo, but they are GET commands and no POST.  not sure what the PROPFIND is, not found much info on that yet.  I think, (reading around), there might be some sort of rewrite going on, that is changing the POST to a GET and killing it, or something.  I am out of my depth at this point though.</p>
  
  <p>Thanks</p>