Hosting Git Repository in Windows

WindowsGit

Windows Problem Overview


Is there currently a way to host a shared Git repository in Windows? I understand that you can configure the Git service in Linux with:

git daemon

Is there a native Windows option, short of sharing folders, to host a Git service?

EDIT: I am currently using the cygwin install of git to store and work with git repositories in Windows, but I would like to take the next step of hosting a repository with a service that can provide access to others.

Windows Solutions


Solution 1 - Windows

Here are some steps you can follow to get the git daemon running under Windows:

(Prerequisites: A default Cygwin installation and a git client that supports git daemon)

Step 1: Open a bash shell

Step 2: In the directory /cygdrive/c/cygwin64/usr/local/bin/, create a file named "gitd" with the following content:

#!/bin/bash

/usr/bin/git daemon --reuseaddr --base-path=/git --export-all --verbose --enable=receive-pack

Step 3: Run the following cygrunsrv command from an elevated prompt (i.e. as admin) to install the script as a service (Note: assumes Cygwin is installed at C:\cygwin64):

cygrunsrv   --install gitd                          \
            --path c:/cygwin64/bin/bash.exe         \
            --args c:/cygwin64/usr/local/bin/gitd   \
            --desc "Git Daemon"                     \
            --neverexits                            \
            --shutdown

Step 4: Run the following command to start the service:

cygrunsrv --start gitd

You are done. If you want to test it, here is a quick and dirty script that shows that you can push over the git protocol to your local machine:

#!/bin/bash

echo "Creating main git repo ..."
mkdir -p /git/testapp.git
cd /git/testapp.git
git init --bare
touch git-daemon-export-ok
echo "Creating local repo ..."
cd
mkdir testapp
cd testapp
git init
echo "Creating test file ..."
touch testfile
git add -A
git commit -m 'Test message'
echo "Pushing master to main repo ..."
git push git://localhost/testapp.git master

Solution 2 - Windows

GitStack might be your best choice. It is currently free (for up to 2 users) and open source at the time of writing.

Solution 3 - Windows

Here's a dedicated git server for windows: https://github.com/jakubgarfield/Bonobo-Git-Server/wiki

Solution 4 - Windows

If you are working in a Windows environment, have you considered Mercurial? It is a distributed version control system like Git, but integrates far more neatly and easily with Windows.

Solution 5 - Windows

If you get the error cygrunsrv: Error starting a service: QueryServiceStatus: Win32 error 1062: The service has not been started. after running the command:

cygrunsrv --start gitd

that means that you did not create the 'base-path' folder.

Creating the folder '/git' and rerunning the command will fix this.

Solution 6 - Windows

Installing CygWin is an overkill, read this tutorial on how to do it faster and native:

http://code.google.com/p/tortoisegit/wiki/HOWTO_CentralServerWindowsXP

Solution 7 - Windows

I'm currently using cygwin's ssh daemon on Windows to serve up and allow remote access to my repo. It works quite well, I have complete control over who accesses my repo by their ssh certificates, and the performance blazes, even over remote WAN and VPN links.

Another solution is to use Gitosis. It is a tool that makes hosting repos much easier.

Solution 8 - Windows

Have you considered using the cygwin layer? See http://fab.cba.mit.edu/classes/MIT/863.07/people/steve/git.html">this link.

Solution 9 - Windows

You do not need to host a service, you can also create a shared repository on a shared drive. Just create a bare repository. You can clone an existing repo into a shared one using: "git clone --bare --shared [source] [dest]". You can also init a new repository using "git init --bare --shared=all".

Henk

Solution 10 - Windows

Now msysGit supports git daemon ! It works fine (for me at least). I gonna try to make it run as service...

Solution 11 - Windows

SCM Manager

  • Lightweight http-server for Git, Mercurial, Subversion repos from a box (only Java is needed)

  • Web-interface for management of users, ACLs, repos

Solution 12 - Windows

On Windows, you can also serve Git repositories with Apache over HTTP or HTTPS, using the DAV extension.

The Git repository path can then be protected with Apache authentication checks such as restricting to certain IP addresses or htpasswd/htdigest type authentication.

The limitation of using htpasswd/htdigest authentication is that the username:password is passed in the requested Git URL, so restricting access to the Git URL to certain IP addresses is better.

Edit: Note, you can leave the password out of the Git URL and Git will prompt you for the password on push and fetch/pull instead.

Using HTTPS means all the data is encrypted in transfer.

It's easy enough to set up, and works.

The following example shows the combination of access control by IP address and user:password over standard HTTP.

Example Apache Virtualhost

## GIT HTTP DAV ##
<VirtualHost *:80>

  ServerName git.example.com
  DocumentRoot C:\webroot\htdocs\restricted\git
  ErrorLog C:\webroot\apache\logs\error-git-webdav.log

    <Location />
      DAV on
      # Restrict Access
      AuthType Basic
      AuthName "Restricted Area"
      AuthUserFile "C:\webroot\apache\conf\git-htpasswd"
      # To valid user
      Require valid-user
      # AND valid IP address
      Order Deny,Allow
      Deny from all
      # Example IP 1
      Allow from 203.22.56.67 
      # Example IP 2
      Allow from 202.12.33.44 
      # Require both authentication checks to be satisfied
      Satisfy all
    </Location>

</VirtualHost>

Example .git/config

[core]
	repositoryformatversion = 0
	filemode = true
	bare = false
	logallrefupdates = true
[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = http://username:[email protected]/codebase.git
[branch "master"]
	remote = origin
	merge = refs/heads/master

Solution 13 - Windows

At work I'm using GitBlit GO installed on a Windows Server. Work flawlessly and integrate well with ActiveDirectory for user authentication and authorization. It is also free and opensource (Apache licensed)

GitBlit homepage

Only HTTP(S) access is supported, no SSH, but under Windows you shouldn't need anything more.

Solution 14 - Windows

this is a 2015 answer to a question that is over 7 years old.

For $10 one time payment, from https://bitbucket.org/product/server, one can purchase a 64-bit Windows licence for up to 10 users.

Apparently 32-bit versions are only available via their archive.

Bitbucket Server was previously known as Stash.

Please note that i have not tried this version but $10 seems like a good deal; here i read that Atlassian gives the $10 to charity. FWIW

Solution 15 - Windows

I think what Henk is saying is that you can create a shared repository on a drive and then copy it to some common location that both of you have access to. If there is some company server or something that you both have ssh access to, you can put the repository someplace where you can SCP it back to your own computer, and then pull from that. I did this for my self a little while, since I have two computers. It's a hassle, but it does work.

Solution 16 - Windows

For Windows 7 x64 and Cygwin 1.7.9 I needed to use /usr/bin/gitd as the args argument of cygrunsrv

cygrunsrv   --install gitd                          \
            --path c:/cygwin/bin/bash.exe           \
            --args /usr/bin/gitd                    \
            --desc "Git Daemon"                     \
            --neverexits                            \
            --shutdown

Also, I needed to run bash as an Administrator to install the service.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJeff FritzView Question on Stackoverflow
Solution 1 - WindowsDerek GreerView Answer on Stackoverflow
Solution 2 - WindowspoiuytrezView Answer on Stackoverflow
Solution 3 - WindowsDaniel OView Answer on Stackoverflow
Solution 4 - WindowsDavid ArnoView Answer on Stackoverflow
Solution 5 - WindowsisaacView Answer on Stackoverflow
Solution 6 - WindowsAlex BurtsevView Answer on Stackoverflow
Solution 7 - WindowsMatthew McCulloughView Answer on Stackoverflow
Solution 8 - WindowsClokeyView Answer on Stackoverflow
Solution 9 - WindowsHenkView Answer on Stackoverflow
Solution 10 - WindowsArtemView Answer on Stackoverflow
Solution 11 - WindowsLazy BadgerView Answer on Stackoverflow
Solution 12 - WindowsDavid ThomasView Answer on Stackoverflow
Solution 13 - WindowsGian MarcoView Answer on Stackoverflow
Solution 14 - WindowsgerryLowryView Answer on Stackoverflow
Solution 15 - WindowsIbrahimView Answer on Stackoverflow
Solution 16 - WindowsdisrvptorView Answer on Stackoverflow