Skip to content

Setup your own git server using gitolite on ubuntu

If you are a developer and want to have a git server with ability to add users push/pull access you might consider something like a github. But why pay for hosting your private projects if you can use your host in the exactly same way? So let’s try to achieve this on an ubuntu server machine.

After a short search I found gitolite, it looks promising.
Let’s start.

1. Let’s install gitolite

cd $HOME
git clone git:// gitolite-source
cd gitolite-source
sudo mkdir -p /usr/local/share/gitolite/conf /usr/local/share/gitolite/hooks
sudo src/gl-system-install /usr/local/bin /usr/local/share/gitolite/conf /usr/local/share/gitolite/hooks

2. Generate your ssh public key for YOUR machine which you are using to connect to the server. Skip this step in case you already have it. You may use this command with defaults answers and empty passphrase.

ssh-keygen -t rsa

3. Copy your LOCAL machine ssh public key to the server. This command will copy the key to your home directory on remote machine.

scp /home//.ssh/ username@

4. On REMOTE machine copy the key to tmp directory like this

cp /tmp/.pub

5. Create git user which will host our repos.

sudo adduser git

6. Login into git user account using password you just gave it

su - git

7. Now run the gitolite setup. It will open config file into vi editor allowing you to edit some values before you setup. I left all the values as is and just quit the editor.

gl-setup /tmp/.pub

8. After setup is completed you have to clone the gitolite-admin repo to your local machine. It will be used for adminstration purposes. The command below depends on your server ssh config. In my case server allows only public key login for certain user. So I had to add git user to AllowUsers line in /etc/ssh/sshd_config.

git clone ssh://

9. At this point we can start creating repos and adding users. I won’t dive in a lot of detail here, I will just do some basic stuff.
Let’s add a repo. Open conf/gitolite.conf in the gitolite-admin dir you cloned to your local machine. You will see two default repos there, just copy one of them like this:

repo    test-repo
RW+     =   test-user

This will create a repo named test-repo and adds read-write access permissions to user identified by test-user public key.

10. Let’s add that key. Obtain it from the user you wish to give access and and rename it to Put the key into keydir directory.

11. Let’s commit our changes to the server for them to take effect.

git add .
git commit -m "created test-repo, added RW+ to test-server user"
git push origin master

12. Now user can do the following in an existing git repo. 12345 is your ssh custom port.

git remote add origin ssh://
git push origin master

Now you can simply create new repos and add users to it. Please do read gitolite documentation to discover its power.

That’s it! Goodbye github! :)


  1. Steve Clay wrote:

    Nice tutorial, and thanks for including the alternate port. For those who never use vi, to quit and save, enter “:q”.

    Tuesday, January 11, 2011 at 9:38 pm | Permalink
  2. Vitali Carbivnicii wrote:

    Thanks :)
    I’m planning to write a follow-up post adding some web ui for repos. And probably auto deploy through ftp functionality.
    But didn’t decide which way to go yet :).

    Tuesday, January 11, 2011 at 10:55 pm | Permalink
  3. Hi,

    Very useful tutorial, well explained!
    BTW, to quit and save VI or VIM, you shoud type “ESC”, to be sure you are exit of the insert mode, and then type “:x”, and not just “:q”, because the “q” is only for quit but not for saving.


    Monday, February 14, 2011 at 6:33 am | Permalink
  4. keydaq wrote:

    You could do worse than exporting your tree and then using sitecopy to FTP sync it.
    I’ve used sitecopy for a number of years with great success. You can find it at

    Saturday, May 21, 2011 at 8:11 pm | Permalink

One Trackback/Pingback

  1. 配置Git服务器的几种方法 | 1个饼 on Monday, March 7, 2011 at 4:39 pm

    […] Gitosis,在ubuntu上设置 2. gitolite:在ubuntu上设置 3. […]

Post a Comment

Your email is never published nor shared. Required fields are marked *