Ad-hoc serving of git repositories


On some occasion you want to serve your git repo from your local copy (perhaps your git repository is quite large and your internet connection is slow or your build process would benefit from pulling from an intermediary without authentication). Here are 2 ways to serve your git repository without any configuration or software installation. Both ways serve a single repository without authentication or encryption but read-only (no push).

Using the git protocol

The git executable is itself a git server using the native git protocol. Inside the root of the repository run the following command

git daemon --reuseaddr --verbose  --base-path=. --export-all ./.git

And on the client you can clone by running

git clone git://servername/ reponame

Using the HTTP protocol

This way serves the repo over HTTP using Python 2's SimpleHTTPServer. Run the following in the rot of the git repo

git update-server-info
cd .git
python -m SimpleHTTPServer

And on the client clone by running

git clone http://servername:8000/ reponame

Final words

I've added both ways as git aliases in my rcfiles repo.