Simple Git HTTP server

The other day I had to share a repo to a colleague without him having access to the online repo.

Conscious that git can serve repositories through HTTP I set myself to discover the simplest way to do it without a full blown git hosting app like GitLab or Gitorious.

At that point I took out my google-fu and came up with the following:

git update-server-info # this will prepare your repo to be served
ruby -run -ehttpd -- . -p 5000
git clone http://localhost:5000/.git repo_name

Now by just knowing your IP anyone will be able to clone that repo.

BONUS

If you’re a PHP nostalgic OSX 10.10 comes with the php command which is able to serve a directory and interpret any PHP file in it (like mod_php would):

git update-server-info # this will prepare your repo to be served
php -S 0.0.0.0:5000 -t .
git clone http://localhost:5000/.git repo_name

Stay tuned for more PHP and Ruby awesomeness!

Returning only an HTTP status code

If your making an API and some methods of your controller doesn’t need to render anything peculiar, you could rely on the head method.

head :ok

For an exhaustive list of the rails mapping you can use the handy cheat gem, created by Josh Susser.

$ gem install cheat
$ cheat status_codes
status_codes:
  Use these codes for the #head or #render methods.  ex:
    head :ok
    render :file => '404.html.erb', :status => :not_found
  
status_codes:
  Use these codes for the #head or #render methods.  ex:
    head :ok
    render :file => '404.html.erb', :status => :not_found
  
  1xx Informational
  
  100 => :continue
  101 => :switching_protocols
  102 => :processing
  
  2xx Success
  
  200 => :ok
...