A friend of mine asked me for some help installing git sever on ubuntu. I wanted to do this myself at home, so I took the opportunity to do it and use that as a document for him. There are a number of good sources online with regard to this type of installation but I found that I needed to piece it together from several of them to get a working system. I chose gitolite for the multiuser component as it seems to be the one most folks recommend.
Server install
To begin with, we had n ubuntu 10.10 system installed and online. You will need to get the necessary git server software installed to begin. This can be done using apt-get:
server
sudo apt-get install git-core sudo apt-get install gitolite sudo apt-get install git-daemon-run |
At this point your server software is installed, and will start up following a reboot.
Add a user
On the client computer you will need to set up ssh key authentication. To generate an ssh key, follow the example below, entering your own password that you want to use to access your git repository.
client
ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (/home/gituser/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/gituser/.ssh/id_rsa. Your public key has been saved in /home/gituser/.ssh/id_rsa.pub. The key fingerprint is: 61:bf:f5:2d:f6:ed:cd:10:b7:0c:be:5d:4d:8f:a3:0d gituser@client |
Once this key is generated you will need to transfer the public version of the key to your git server. You can do this using scp:
client
scp /home/gituser/.ssh/id_rsa.pub user@gitserver:/tmp/gituser.pub |
Now you need to go back to the gitserver and add this key to git:
server
chmod 666 /tmp/gituser.pub su gitolite gl-setup /tmp/gituser.pub |
Now you have added a user to the git server.
Client configuration
There is very little to do to allow your client to connect to the git server now, and really I only set up the following for myself:
client
git config --global user.name "firstname lastname" git config --global user.email email@email.com |
Adding a repository to your new git server
Finally, lets set up a test repository. To do this we need to first check out the gitolite-admin repository from the git server and edit the configuration file and then check it back in.
client
git clone gitolite@server:gitolite-admin cd gitolite-admin/ vi conf/gitolite.conf |
This file should already contain a couple of repositories:
client
repo gitolite-admin
RW+ = gituser
repo testing
RW+ = @all |
You can create a new repository by adding a couple of lines to the bottom of that file:
client
repo mytest
RW+ = gituser |
Save that file, and we can then commit it back to the server:
client
git commit -m "Added mytest repo" conf/gitolite.conf git push |
You should see output like the following, this creates the repository on the git server:
client
Counting objects: 7, done. Delta compression using up to 2 threads. Compressing objects: 100% (3/3), done. Writing objects: 100% (4/4), 398 bytes, done. Total 4 (delta 1), reused 0 (delta 0) Already on 'master' creating mytest... Initialized empty Git repository in /var/lib/gitolite/repositories/mytest.git/ To gitolite@gitserver:gitolite-admin 610d463..98a9226 master -> master |
Now that we have a new repository, we can clone it to our local client system and add files to it:
client
cd git clone gitolite@gitserver:mytest cd mytest echo â??This is a testâ? > readme.txt git add . git commit -m "Initial checkin of readme.txt" git push origin master |
Now you can delete that entire directory and clone it back from the server again and you will find your readme.txt file again. Very cool!
External links
These 2 sites are a great resource to understanding git and how to do different tasks.
http://www-cs-students.stanford.edu/~blynn/gitmagic/
http://help.github.com/git-cheat-sheets/
I’d also recommend you get a hold of the Pro Git book:
Well, happy coding now!








[...] This post was mentioned on Twitter by coLLin LeGault, coLLin LeGault. coLLin LeGault said: New Post:: How to configure a git server on Ubuntu 10.10 http://bit.ly/ed12a3 #git [...]
This is a great article Collin!
I have to say that topic branching is becoming one of my favorite features in git. EXTREMELY handy!!
Hi coLLin,
Thanks for your article. I followed your steps above, and it worked.
I have one question. Where can I view the git code in the server? They must store somewhere in the server which I can’t find at the moment.
Thanks,
Luan
Hi Luan,
It stores the history as a compressed collection of interrelated snapshots of the projectâ??s contents. Everything you have in your .git directory of a cloned project is considered a “bare” git repository. The source code that you view outside of the that .git directory is what is currently “checked out” from the “bare” repository. Newly created objects are initially created in a file named after the objectâ??s SHA-1 hash (stored in .git/objects). You can read a lot more about it from the git user manual found here:
-coLLin
Hi coLLin,
Thanks for your time and explanation. I understand it now. I just read chapter 1 and chapter 2 from the pro-git book from the your site. Thanks a lot for your help again. Good stuff!
Luan
Hi Luan,
Glad you could use it! BTW, I should point out that gitolite uses /var/lib/gitolite as its home directory, so your “bare” repo and gitolite configurations and project list all reside under that directory, in the event that you want to move it off to an NFS or Samba or AFP share.
I was wondering which steps should I change/add and how to connect to an existing git repository provided by a customer. I have the repository url, ssh keypair with the password, server IP and username. Thanks.
Create the repo on the server side and then check it out to your local machine in a new directory. Inside that directory will be a config file in the .git directory. Open this .git/config file, and then copy your current git remote=”origin” line that refers to url (i.e. url = gitolite@git:gitolite). Replace this line in your existing git repo .git/config file, and then do a push in that directory. Hope this helps, sorry it took so long to respond, holidays and all. Let me know if you get stuck.
Thank you for the simple guidance, making understand of using the git server.
I used your article to set up a local git server and i’m kind of stuck in configuring a windows client… Do you have a “How to” for windows clients like TortoiseGit??? If there is any mistake in my english, sorry about that i’m brazilian and self thaught.
Hi, I have tried to run the guide on my Ubuntu 11.10 box. When I run “su gitolite gl-setup /tmp/gituser.pub” all I get is “Unknown id: gitolite”
Can you point me in the right direction?
Thanks.
Hi Brian, thanks for the comment, I haven’t tried this on 11.10 yet, obviously it will have some differences. Looks like you are missing the group gitolite. You should be able to
groupadd gitoliteto correct it. I will look at setting it up on 11.10 and make a new tutorial.Oi Marcos,
Desculpe pela minha resposta atrasada. Por favor, olhe este link para obter ajuda para Windows: http://lostechies.com/jasonmeridth/2009/06/01/git-for-windows-developers-git-series-part-1/
Hi, since a long time i tried to set up a private git server for my projects but all the tuts i’ve seen was very cryptic. I found your very easy to follow and i’m pretty happy with my new repo.
I just wanted to thank you for your tutorial.
Glad to hear it! I found them to be pretty cryptic as well which is why I wrote this one. I think I need to put out a newer version of it though, 10.10 is getting a little long in the tooth.
Thanks!