110

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.

Jeff Fritz
  • 9,821
  • 7
  • 42
  • 52
  • 37
    My current employer does not have any Unix or Linux machines... bringing in a new Source Control provider and operating system at the same time may be a bit... traumatic. – Jeff Fritz Oct 24 '08 at 16:01
  • 1
    What’s wrong with git-daemon? AFAIK it works just fine on Windows. – Aristotle Pagaltzis Oct 24 '08 at 17:05
  • 10
    Installing Git using the standard msysgit installer for Windows doesn't appear to install `git daemon`. :\ – Tim Visher Jan 26 '09 at 16:22
  • 1
    [There's a bundled CopSSH and msysgit installer](http://windowsgit.com) that you might want to look at. It uses public key authentication, and makes it easy. Disclaimer: I'm the webmaster - I started the project after reading [Tim Davis' tutorial on setting up a secure git server.](http://www.timdavis.com.au/git/setting-up-a-msysgit-server-with-copssh-on-windows/) – Lilith River May 27 '11 at 14:11
  • 3
    For the record: Git for Windows has included a working version of git daemon since version 1.7.4 (released February 2011). So cygwin is no longer required. See also http://stackoverflow.com/q/5186070/291641 – patthoyts Oct 26 '12 at 09:50

16 Answers16

75

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
Derek Greer
  • 15,454
  • 5
  • 45
  • 52
  • 2
    If I could edit this post, I would add the following: Prerequisites: cygwin with the packages git and cygrunsrv installed. – Mario Mar 05 '10 at 15:36
  • Ah, yes. I guess I assumed too much. – Derek Greer Mar 12 '10 at 20:02
  • 2
    Another note: fully qualify the path to git inside of the gitd shell script. On one of my machines MSYSGit was being started instead of cygwin-git when executing as a windows process. MSYSGit does not support daemon mode so the service failed to start. – Mario Mar 16 '10 at 05:19
  • I modified per your suggestion. – Derek Greer Mar 20 '10 at 17:15
  • Until now, I've heard that you can't push to a git remote based on git protocol, as it is read-only. Am I wrong? did you really did a push to it like you show in your last line? – Herberth Amaral Feb 19 '11 at 23:14
  • 27
    I never took Cygwin solutions as "working in Windows". It's like saying "running linux in a VM is working in Windows". But that's just my puristic opinion ;) – Rook Feb 26 '11 at 12:49
  • Is there any IPv6 considerations? I can't clone from localhost in Windows 7. I got error: fatal: unable to connect a socket (No Error) – Afshar Mohebi Apr 15 '11 at 06:15
  • The installation worked. Can I access the serveur over the internet ? Can I change the port the git server listens to ? – Manu Sep 19 '12 at 10:09
  • 1
    @Herberth Amaral - Sorry, just reading this. Yes, that's what the --enable=receive-pack does for you. – Derek Greer Sep 26 '12 at 14:33
  • 3
    quick note: /usr/bin didnt work for me but placing in /bin worked (and using c:/cygwin/bin/gitd in the cygrunsrv). Not sure how old my cygwin install is but looks like /usr/bin is a link to whats in /bin which windows wont know about... Also kinda obvious, but remember to create the folder /git in c:/cygwin/ – armyofda12mnkeys Jan 10 '13 at 12:50
  • 1
    When attempting to start the service, if you get the error "Error starting a service: QueryServiceStatus: Win32 error 1062: The service has not been started" then it means you didn't create the git folder (`/cygdrive/c/cygwin/git`) – Adam Tuttle Feb 17 '13 at 13:43
  • 3
    @Rook - On the contrary, the Cygwin suite of tools are no different than any other 3rd-party applications you might install. Cygwin isn't a virtual machine, but a pre-packed suite of tools. It's just a set of Windows executables and dlls like everything else on your machine. – Derek Greer Mar 19 '15 at 13:01
  • Note: At some point msysgit was updated to include daemon support, so using the Cygwin distribution of git is no longer necessary. – Derek Greer Mar 19 '15 at 13:12
  • All I see is a "deamon.pm" script with Git for Windows. Is running this Perl script a recommended/common approach? – ryanwebjackson Feb 09 '21 at 21:21
16

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

M4N
  • 94,805
  • 45
  • 217
  • 260
poiuytrez
  • 21,330
  • 35
  • 113
  • 172
  • 2
    Looks like that was restricted to open source or student projects: "GitStack is free for open source & student projects!" – ccellar Jun 28 '12 at 10:36
12

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

Daniel O
  • 2,810
  • 3
  • 28
  • 35
  • What's the state of the Bonobo server? Is it fully functional? I can't tell from the documents, but it looks very compelling. – Jeff Fritz Jun 03 '11 at 12:32
  • 1
    @JeffFritz: just stopped using it. The darn thing doesn't update repository state (`git update-server-info`) after HTTP push, and this logic is not implemented by their Git library (GitSharp). I doubt it will reach a real working state any time soon. – André Caron Sep 26 '11 at 16:59
  • Also, doesn't work with Teamcity (which is the main reason for me not using it) https://github.com/jakubgarfield/Bonobo-Git-Server/issues/11 – Piers Karsenbarg Feb 11 '13 at 16:17
  • 3
    Happy Bonobo user here. I believe both Andre and Piers concerns should be resolved now. That TeamCity issue was marked closed and I haven't experienced any problems with using a central centralized repository. – Quinn Bailey Nov 14 '13 at 18:03
9

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.

David Arno
  • 42,717
  • 16
  • 86
  • 131
  • 9
    It's true that it's much easier to use Mercurial on Windows machines, at least as far as being able to synch repositories is concerned. Not a terribly useful answer if you actually have to use Git though! – Frank Shearar Mar 10 '10 at 09:10
  • Also Bazaar works natively on windows; it even has commercial support. – hasen Mar 12 '10 at 23:21
7

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.

Nathan Tuggy
  • 2,237
  • 27
  • 30
  • 38
isaac
  • 71
  • 1
  • 1
  • You can also get this error if your `/git` NTFS permissions don't allow the service account (SYSTEM) read/write access. – spoulson Jan 23 '12 at 15:45
7

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

Alex Burtsev
  • 12,418
  • 8
  • 60
  • 87
  • 2
    I'm late to the party, but this link now redirects to https://tortoisegit.org/ which talks all about the client. I can't find anything about running a server there. – Richard A Apr 01 '20 at 22:07
5

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.

Matthew McCullough
  • 17,160
  • 7
  • 39
  • 38
  • How did you get the git daemon working with cygwin? I have the ssh daemon setup and I've testing logging into my machine via ssh but whenever I try to run the git daemon it just hangs. – Thiru Mar 31 '09 at 00:29
  • How did you get gitosis working on windows as there is a bug: http://github.com/res0nat0r/gitosis/issues#issue/1 – dalore Jun 16 '10 at 14:53
4

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
Lazy Badger
  • 94,711
  • 9
  • 78
  • 110
4

Have you considered using the cygwin layer? See this link.

Josh Stodola
  • 81,538
  • 47
  • 180
  • 227
Clokey
  • 645
  • 2
  • 8
  • 15
4

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

Artem
  • 41
  • 1
  • does it support both push and pull? Because there is an issue http://code.google.com/p/msysgit/issues/detail?id=457 when doing pushes. – Vadim Feb 26 '11 at 14:24
  • So have you got this running as a service? Do you know of a "getting started" guide? – Craig McQueen Sep 10 '12 at 02:17
4

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

Henk
  • 247
  • 3
  • 3
  • 3
    Yes, you can create a shared repository on a drive, but I will NOT be able to access that repository unless I am on the same network as the repository. The goal of the question is to allow remote access to a repository for a co-worker who is working off-site – Jeff Fritz Apr 16 '09 at 15:32
  • 3
    This is not really a solution to the question and seems like a pretty questionable thing to do anyway. – Pat O Nov 22 '10 at 14:17
2

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.

Gian Marco
  • 22,140
  • 8
  • 55
  • 44
2

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:password@git.example.com/codebase.git
[branch "master"]
    remote = origin
    merge = refs/heads/master
David Thomas
  • 4,027
  • 3
  • 28
  • 22
1

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

gerryLowry
  • 2,626
  • 5
  • 35
  • 44
0

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.

disrvptor
  • 1,592
  • 12
  • 23
0

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.

Ibrahim
  • 1,883
  • 19
  • 27