Brain Phrye

code cooking diy fiction personal photos politics reviews tools 


Git http Serve

Sometimes it’s really handy to be able to serve out a git repo from your laptop. Say you’re at a conference or on a plane and lack an external net connection but can make a local network connection between you. Or you want to do some sort of local testing of a git clone or pull.

I needed to do that recently and came across this article which described a really quick way to do it - though it’s instructions were a bit off. The really quick way to do it is this:

1
2
3
4
git clone --bare YOUR_REPO_DIR YOUR_REPO_DIR_BARE
cd YOUR_REPO_DIR_BARE
git --bare update-server-info
python3 -m http.server 8000

You should now be able to do git clone http://YOUR_IP:8000/ REPO on the other machine. At this point you can’t push though. So you’d need to do this one extra step for that (I think) in the YOUR_REPO_DIR_BARE dir: mv hooks/post-update.sample hooks/post-update.