Taming The Git-Daemon To Quickly Share Git Repository


I was once in a hurry to share GitHub repository with a colleague who didn’t have access to it and we decided to use local git-daemon. However, handling all the little quirks that would make it work took a lot more efforts than just dropping a repository archive via Skype.

From this article you will learn how to easily share read/write access to the local git repository. Additionally, I will share two simple aliases for git that will make this task a real no-brainer for anyone.


Please note that this is an insecure way of sharing access to git repository and should be used only in a friendly LAN-environment. If you need secured solution, consider using SSH-protected way.

Sharing read-only access

Next command shares read access(clone/pull) to any repository in current directory:


  • –export-all – shares all the repositories in a folder from “–base-path” option
  • –base-path=. – daemon looks for repositories in a current directory(“.”)
  • –reuseaddr – allows to restart server quickly
  • –informative-errors – provides cleaner error message for clients
  • –verbose – notifies about each operation with the repository

Sample flow

1) Run git-daemon in directory with your repos:

2) Now clients can clone/pull this repository:

Instead of the “″ client should use the IP of your computer.

Sharing push access

Add “–enable=receive-pack” option and git-daemon starts supporting push access:

There is one quirk: client can’t push into your active git branch. Before pushing, user on the server should change the branch, if client wants to push to this branch.

Another option can be for the client to create a new branch and push it to your server. Then you can merge it into a required branch.

Sample flow

1) Run git-daemon in read/write mode:

2) Client clones repository:

3) Client branches-off, makes changes and pushes back new branch:

4) Now on Server you can merge this branch:

Sharing only one repository

If you want to share only some repositories, you’ll need to remove “–export-all” option and create “git-daemon-export-ok” file in .git directory of the appropriate repositories.

Sample flow

1) Create magic file:

2) Run git-daemon without “–export-all” option:

3) Client can’t access non-shared repository:

4) Client can access shared repository:

Making life simpler with aliases

Let’s create git aliases for read-only and read/write sharing. Here is what it should look like in .gitconfig:

Notice “!”-symbol in front of the aliases. This is a way to alias external shell command, and with this trick we can call these commands outside of git repository.

Next commands automatically put these aliases into .gitconfig:

Now with “git serve” you can share read access and with “git hub” – read/write access to our repositories. “git serve” resembles Mercurial “hg serve” which performs exactly the same operation. And “git hub” feels to be just right for read/write sharing, don’t know why.

Once the aliases are added, we can run and see “hub” command in action:

Yay, it works!

That’s it, and as I promised – it’s a real no-brainer to share anything using these magic aliases.

* Railsware is a premium software development consulting company, focused on delivering great web and mobile applications. Learn more about us.
  • Sergii

    Very handy, thanks!

  • Brad

    When my local repo is changed by another user who added me as a remote and pushed changes back to me, I don’t see their changes. Is there a cache or something that needs to be refreshed so that I can see changes pushed to my local repo from remote users? Thanks!

Want to get more of Railsware blog?


We're always ready to help!