Git: Anonymous Access Under Windows
The Git version control system provides a simple protocol for sharing Git repositories anonymously over a TCP port. This can be useful for providing read-only access to a repository, or for facilitating pull-based collaboration within teams. The following is a guide for setting up and sharing a Git repository anonymously under Windows using Cygwin.
Step 1: Install Cygwin with the cygrunsrv and desired git packages:
Step 2: Create a file named gitd
in the /usr/sbin
directory with the following content:
#!/bin/bash git daemon --reuseaddr --base-path=/cygdrive/c/Projects
By default, the git daemon only shares folders under the base path which contain a file named git-daemon-export-ok
. If you wish to share all folders under the base path without requiring this file, use the switch --export-all
.
This command assumes the base path of all shared git repositories will be /cygdrive/c/Projects/
(i.e. C:Projects
under Windows). Change this value if your projects are stored in an alternate location.
If you wish to enable anonymous push access to your repositories (not advisable), you can add the switch --enable=receive-pack
.
cygrunsrv
command to install the script as a service (Note: This command assumes Cygwin is installed at C:Cygwin
):</p>
cygrunsrv --install gitd --path c:/cygwin/bin/bash.exe --args c:/cygwin/usr/sbin/gitd --desc "Git Daemon" --neverexits --shutdown
Step 4: From a bash shell prompt, run the following command to start the service:
cygrunsrv --start gitd
The gitd service should now be running. To verify that everything is setup properly, here is a quick and dirty script which should establish that the desired repositories are remotely accessible:
#!/bin/bash BASEDIR=/cygdrive/c/Projects REPO_NAME=testapp$$ REPO_PATH=${BASEDIR}/${REPO_NAME} REMOTE_PATH=${BASEDIR}/remote$$/ echo "Creating a local git repo ..." mkdir -p ${REPO_PATH} cd ${REPO_PATH} git init touch .git/git-daemon-export-ok echo "Commiting test file ..." touch testfile git add -A git commit -m 'Test message' echo "Simulate remote clone ..." mkdir ${REMOTE_PATH} cd ${REMOTE_PATH} git clone git://localhost/${REPO_NAME} echo "Cleaning up test folders ..." rm -rf ${REPO_PATH} rm -rf ${REMOTE_PATH}