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.


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 -t .
git clone http://localhost:5000/.git repo_name

Stay tuned for more PHP and Ruby awesomeness!

Recover staged files after git reset –hard

Ok you want to get rid off of your unstaged file in a git repo.


git add .  
git reset --hard

But wait…what?…no!!! Some of the unstaged files were actually necessary! They had to be in .gitignore! What about now?!

Don’t despair and type:

git fsck --lost-found

Now you can go in the newly created directory .git/lost-found/other/ and find all the files that were deleted by the destructive git reset --hard.

The only problem is that their original names aren’t retained 🙁

Anyway if you remember the content of the files that should be actually retained you can check manually each one of those in .git/lost-found/other/ and copy them back in their original location.