141

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.

Jonas
  • 2,910
  • 2
  • 26
  • 36
Setori
  • 10,326
  • 11
  • 40
  • 46
  • Are you aware that cloning a git-svn clone of an svn repo is tricky? http://subtlegradient.com/articles/2008/04/22/cloning-a-git-svn-clone – bendin Dec 18 '08 at 09:06
  • Why not just install svn on your linux notebook ad use check out from the project repository directly? Git may be the new hotness, but it really seems like you're making your life unnecessarily complicated in this particular case. – bendin Dec 18 '08 at 09:08
  • bendin no i didnt know it was tricky, as im setting up the environment now im glad you spoke up... – Setori Dec 18 '08 at 09:20
  • 1
    Firstly: my notebook is not allowed onto this vpn, so I cannot access the svn directly. secondly: I want to commit to my own repository, the whole point of using git is so I can do local commits, branch and painlessly merge. I find using svn now rather cramping. – Setori Dec 18 '08 at 09:22
  • If you have python installed, a simple `git instaweb -d python` could be nough (with Git 2.21, Feb. 2019): see [my answer below](https://stackoverflow.com/a/54971723/6309) – VonC Mar 03 '19 at 17:35

8 Answers8

198

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
Rich O'Kelly
  • 41,274
  • 9
  • 83
  • 114
seanhodges
  • 17,426
  • 15
  • 71
  • 93
  • 3
    You can add the command as an alias to you .gitconfig file as described here: http://git.or.cz/gitwiki/Aliases#Serverepoonthespot – RFelix Jul 07 '09 at 16:08
  • 1
    that should be http://git.wiki.kernel.org/index.php/Aliases#Serve_repo_on_the_spot – Aeon Mar 16 '10 at 00:33
  • Thanks a bundle. Have been searching for that for some time. – wwerner Nov 19 '10 at 10:54
  • 8
    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. – Rob Kennedy Feb 25 '11 at 06:37
  • And if you get `git: 'daemon' is not a git-command` you need to upgrade your git installation. – Roman Starkov May 16 '11 at 11:21
  • If you start git deamon in background mode, it may not work with --verbose option. – Dziamid Oct 29 '10 at 14:04
  • 4
    make serve an alias in your .gitrc like : `serve = !git daemon --reuseaddr --verbose --base-path=. --export-all ./.git` – dlamblin Nov 09 '11 at 21:51
  • 1
    @Aeon, it seems URLs have changed and it's now https://git.wiki.kernel.org/articles/a/l/i/Aliases.html – Christophe Muller Jan 16 '12 at 13:41
  • Thanks for the broken link fix guys. – seanhodges Jan 19 '12 at 11:57
  • 2
    Also, you need the `--enable=receive-pack` parameter if you wish to enable pushes. [[Source](http://stackoverflow.com/questions/792611/receive-pack-service-not-enabled-for-git)] I've documented this a bit on [this gist](https://gist.github.com/mx4492/1b144418911b48824919) – Manav Jul 09 '14 at 06:27
  • What can you do if you have multiple repos? – Steve Smith Feb 03 '23 at 16:07
14

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.

Otto
  • 18,761
  • 15
  • 56
  • 62
13

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 .

criskiev
  • 152
  • 1
  • 6
12

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

git-instaweb

$ git instaweb -d apache2 --start
$ lynx localhost:1234
Matt Ball
  • 354,903
  • 100
  • 647
  • 710
John Mee
  • 50,179
  • 34
  • 152
  • 186
  • it says `lighttpd not found. Install lighttpd or use --httpd to specify another httpd daemon.` – Rakib Oct 10 '11 at 13:21
  • 4
    @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. – Martijn Heemels Feb 04 '12 at 18:31
  • 6
    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. – Robert MacLean May 28 '12 at 15:29
9

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/

bara
  • 2,964
  • 2
  • 26
  • 24
0

git-webui is a git extension which provides a web based user interface and the ability to clone/pull from other computers

https://github.com/alberthier/git-webui

$ cd my_git_repo
$ git webui

Other people can

$ git clone http://<ip-of-your-computer>:8000/ repoclone

or

$ git pull http://<ip-of-your-computer>:8000/
alberthier
  • 643
  • 1
  • 7
  • 9
  • 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. – uss Mar 03 '15 at 04:26
0

Add following lines in .git/config

[instaweb]
               local = true
               httpd = webrick
               port = 4231

then execute

git instaweb
Nayagam
  • 1,767
  • 18
  • 12
0

Git 2.21 (Feb. 2019) allows you to combine python and git instaweb:

See commit 2eb14bb (28 Jan 2019) by Arti Zirk (artizirk).
(Merged by Junio C Hamano -- gitster -- in commit abf39e3, 05 Feb 2019)

git-instaweb: add Python builtin http.server support

With this patch it is possible to launch git-instaweb by using Python http.server CGI handler via -d python option.

git-instaweb generates a small wrapper around the http.server (in GIT_DIR/gitweb/) that address a limitation of the CGI handler where CGI scripts have to be in a cgi-bin subdirectory and directory index can't be easily changed. To keep the implementation small, gitweb is running on url /cgi-bin/gitweb.cgi and an automatic redirection is done when opening /.

The generated wrapper is compatible with both Python 2 and 3.

Python is by default installed on most modern Linux distributions which enables running git instaweb -d python without needing anything else.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250