Git serve: I would like it that simple

20,503

Solution 1

Navigate into your project and start git-daemon with the following switches:

cd project
git daemon --reuseaddr --base-path=. --export-all --verbose

This tells git-daemon to serve up all projects inside the current directory (which I assume is the project directory containing the .git/ folder). It also tells it to re-use the same address if you shut it down and start it back up too fast.

You can put this into a batch script with an easy to remember name like "gitserve", so you don't need to type it all out again. As suggested in some of the comments, in recent versions of Git you can add an alias to the Git config:

[alias]
    serve = !git daemon --reuseaddr --verbose --base-path=. --export-all ./.git

Once that's done on the server (your Windows box), you can do:

git serve

git-daemon uses the git:// protocol for transport, so on the client (your Linux box), you would need to do:

git clone git://123.456.789.111/ project

Solution 2

Rather than write your own batch script, use gitjour. It knows how to start git daemon correctly and will broadcast the clone URL via mDNS so you can do gitjour show on the linux box and copy and paste.

Also a good article with an overview of gitjour and a number of other similar tools from Dr. Nic, What is *jour and why they are killer apps for RailsCamp08.

Solution 3

Currently using two aliases - serve and hub. Serve for read-only share and hub for read/write share:

[alias]
  serve = !git daemon --base-path=. --export-all --reuseaddr --informative-errors --verbose
  hub = !git daemon --base-path=. --export-all --enable=receive-pack --reuseaddr --informative-errors --verbose

Also, there is more detailed tutorial about sharing via git daemon: http://l.rw.rw/git-daemon .

Solution 4

If you just want to expose the repository with a web browser

git-instaweb

$ git instaweb -d apache2 --start
$ lynx localhost:1234

Solution 5

Here is an alternative way. You will need python installed.

  • run git update-server-info
  • go to the .git directory
  • run python -mSimpleHTTPServer

(just create an alias in your gitconfig)

Now you can pull the repo with git pull http://HOST_NAME:8000/

PS: when usingthe git daemon solution you can set --base-path=.git so the url is git://HOST/

Share:
20,503
Setori
Author by

Setori

Updated on July 08, 2022

Comments

  • Setori
    Setori almost 2 years

    I want to know how to simply publish over http = much like Mercurial's hg serve! On the Windows/work box do this:

    git serve 
    

    and then on the Linux box SIMPLY go:

    git clone http://project project 
    

    finished.

  • RFelix
    RFelix almost 15 years
    You can add the command as an alias to you .gitconfig file as described here: git.or.cz/gitwiki/Aliases#Serverepoonthespot
  • Aeon
    Aeon over 14 years
  • Dziamid
    Dziamid over 13 years
    If you start git deamon in background mode, it may not work with --verbose option.
  • wwerner
    wwerner over 13 years
    Thanks a bundle. Have been searching for that for some time.
  • Rob Kennedy
    Rob Kennedy over 13 years
    I think it's important to note that although git daemon allows for remote access by other git clients, it lacks the Web interface that hg serve provides.
  • Roman Starkov
    Roman Starkov about 13 years
    And if you get git: 'daemon' is not a git-command you need to upgrade your git installation.
  • Rakib
    Rakib over 12 years
    it says lighttpd not found. Install lighttpd or use --httpd to specify another httpd daemon.
  • dlamblin
    dlamblin over 12 years
    make serve an alias in your .gitrc like : serve = !git daemon --reuseaddr --verbose --base-path=. --export-all ./.git
  • Christophe Muller
    Christophe Muller over 12 years
    @Aeon, it seems URLs have changed and it's now git.wiki.kernel.org/articles/a/l/i/Aliases.html
  • seanhodges
    seanhodges over 12 years
    Thanks for the broken link fix guys.
  • Devplex
    Devplex over 12 years
    @syedrakib You'll need to have lighttpd installed, or apache2, or something else. Personally I use git instaweb -d webrick on OS X, because webrick comes with Ruby, which is preinstalled on OS X.
  • Robert MacLean
    Robert MacLean about 12 years
    This tool doesn't seem to be Windows compatible. As the poster was asking for a Windows tool, that is an important factor for this answer.
  • Manav
    Manav almost 10 years
    Also, you need the --enable=receive-pack parameter if you wish to enable pushes. [Source] I've documented this a bit on this gist
  • uss
    uss over 9 years
    I just tried with it blindly. I am able to git clone but not able to access the webgui. It looks the browser is waiting for a response from your server.