Setting up a git server in Ubuntu with gitosis and using gitextensions on Windows
When writing code, you want to use some sort of version control system. Trust me, you want it. I had a project I worked on for 4 weeks and a couple of hours before the deadline I mad a mistake. I was making a class diagram from existing code and realized that a certain UML tool thinks it’s a good idea to delete a class from the project folder when you decide that you don’t want that particular class in your diagram. I guess that makes sense… on a planet where all software developers are masochists. Anyway, that little mistake could have been a serious problem (and a simple “Oops, sorry I deleted all the code by accident, kthxbye” wouldn’t have cut it), but luckily I had it stored in my dropbox folder which backs everything up on the dropbox servers and they provide an ‘undelete’ option.
I’ve been trying to setup a git server on my server which runs Ubuntu Server 9.10, but I had a lot of problems partly due to the fact that I couldn’t find a lot of information when something went wrong. But I’m a stubborn person so I persevered and succeeded in the end. This post is for those who want to setup a git server on Ubuntu and want to use git on Windows, especially with Git Extensions. This tutorial consists of two parts: setting up the server and setting up gitextensions on Windows, but there will be some switching between the server and the local Windows machine so please pay attention.
There are a lot of tutorials that cover setting up a git server but this one is a full guide to setting up a git server and the tools necessary to work with git on Windows. It also has some information I found on some mailing lists and forum posts that I found after a lot of searching. Still I take no credit for this tutorial for it is merely a collection of information I found. All credit goes to the people who actually tested these steps and bothered putting it on the internet for other people struggling with this. I try to explain everything as thorough as possible so it is a lot of text, but it’s not hard. Just read carefully and you will have git running in no time!
Setting up the git server
The server will use the git repository manager Gitosis. It’s easy to setup and it just works
1. Install Ubuntu Server (or any other flavor of Ubuntu) on your server and select the OpenSSH Server option when asked which packages you want to install. If you don’t do this or you forget it, don’t worry, we can add it with a simple command later.
2. Update your server:
sudo apt-get update
sudo apt-get dist-upgrade
You can also do sudo apt-get upgrade if you want, but if you’ve installed a fresh copy of Ubuntu you might as well fully update it. If you haven’t installed the OpenSSH Server option install it with:
sudo apt-get install ssh
3. Install the git-core package so we can use git.
sudo apt-get install git-core
4. Install the python-setuptools package which is needed by Gitosis.
sudo apt-get install python-setuptools
5. Now we can get Gitosis and set it up.
mkdir ~/src
cd ~/src
git clone git://eagain.net/gitosis.git
If everything went fine you should see something like this:
Initialized empty Git repository in /home/oguz286/src/gitosis/.git/
remote: Counting objects: 614, done.
remote: Compressing objects: 100% (183/183), done.
remote: Total 614 (delta 434), reused 594 (delta 422)
Receiving objects: 100% (614/614), 93.82 KiB | 134 KiB/s, done.
Resolving deltas: 100% (434/434), done.
6. Time to install Gitosis.
cd gitosis
sudo python setup.py install
7. Setup the ‘git’ user.
sudo adduser \
–system \
–shell /bin/sh \
–gecos ‘git version control’ \
–group \
–disabled-password \
–home /home/git \
git
The –home option need not be /home/git (I placed it on the RAID5 array in my server, instead of the system disk where the /home folder resides). Notice that the git user doesn’t have a password. This is because we will be using ssh keys to access our repositories.
Attention: we will switch to the local machine because we need to generate the ssh keys needed by Gitosis but we are not with the server just yet.
Setting up gitextensions on Windows
8. Get Git Extensions and install it on your local Windows machine. I opted for the option to only add git to my path, so I recommend you do the same since I’m not sure if it’s necessary. The other default options are just fine so don’t change them.
9. Start Git Extensions and follow the instructions (you probably need to fill in your name and email address that is shown when you commit something). Now click ‘Remotes->PuTTY->Generate or import key‘.
This will open PuTTYgen, which we will use to generate our ssh keys. Click on ‘Generate‘ and follow what’s on the screen. After some the keys will be generated. Change the ‘Key comment‘ section to your username but make sure it has no spaces! This is important because Gitosis will use it as your username and ‘rsa-key-2010xxxx’ is a horrible representation of a user. I chose ‘OguzMeteer’ because that is my full name.
Make a new file on your desktop called ‘id_rsa.pub‘ and put the long string under the ‘Public key for pasting…’ section in that file and put that file on your server (in this example in the /tmp folder).
Click on ‘Save private key‘ and put the file somewhere safe. You will need it shortly.
Attention: the next step is performed on the server!
8. Add your public key to Gitosis.
sudo -H -u git gitosis-init < /tmp/id_rsa.pub
You can do this for each person you want to grant access to your repositories.
If everything went allright you should see something like this (depending on where your git user home is):
Initialized empty Git repository in /home/git/repositories/gitosis-admin.git/
Reinitialized empty Git repository in /home/git/repositories/gitosis-admin.git/
Yes it initializes and re-initializes, so don’t worry. And with that you are done with the server!
9. Connect to your server.
Use PuTTY to connect to your server once. This is needed because the first time you connect a server who’s public key is not known on your system it asks you if you want to accept its public key. Select ‘yes’ after connecting to your server and then close PuTTY.
10. Configure Gitosis.
This is the cool part because we will configure Gitosis by using git! In Git Extensions click on ‘Clone repository‘. You will see this:
For ‘Repository to clone‘ fill in:
git@yourserverip:gitosis-admin.git
Attention: do not add a ‘\’ after it, because then you will get error messages about the command looking dangerous and the server will close the connection! Git Extensions puts it there sometimes so look out.
‘Subdirectory to create‘ usually is the same name as the repository you want to clone so fill in ‘gitosis-admin’.
Click on ‘Load SSH key‘, select your private key and load it. You will notice that an icon will appear in your taskbar. It is ‘Pageant’ and it needs to run when you want to connect to your git repository. Most screw-ups are made here. If it isn’t running you cannot connect to you repository so make sure it is running. You can also access it through ‘Remotes->PuTTY->Start authentication agent‘. If you open it you will see that your private key is in the list and your username that you filled in the comment section is also there.
Finally click on ‘Clone‘ and you should get the result you wanted
Git Extensions asks you if you want to open the repository you just cloned. Do that and you will see the history of the repository (which consists of only 1 commit).
Now you are ready to make your own repositories!
Setting up repositories
Let’s say you have a new project called ‘myproject‘ and want to make a repository for it on your new server. Open up gitosis.conf in the directory you cloned it to. Mine contains this:
[gitosis]
[group gitosis-admin]
writable = gitosis-admin
members = OguzMeteer
Let’s add ‘myproject‘ to it. Modify it like this:
[gitosis]
[group gitosis-admin]
writable = gitosis-admin
members = OguzMeteer[group whatever]
writable = myproject
members = OguzMeteer
We’ve made a new group called ‘whatever‘. You can name it whatever you want. What’s important is the ‘writable‘ section where the name of your repository is filled in. ‘members‘ obviously is for who has access to the repository. Remember that the name of each member you want to grant access has to be exactly like what you (and they) filled in, in the comment section when generating an ssh key pair (no spaces!).
Now make a folder called myproject and create a new empty repository in it. To do this click ‘File->Close‘ and then click ‘Create new repository‘ in your already opened Git Extensions. Select your myproject folder and click ‘Initialize‘. Add some files in the folder and then click ‘Commit‘. Select the files and click ‘Stage selected files‘, write a message and then click ‘Commit‘.
There are only 2 steps left so hang in there! Click ‘Remotes->Manage remote repositories‘ and fill in like in this picture and click ‘Save‘:
Click ‘Yes‘. You will probably get an error, but don’t worry about it.
And the final step! Click ‘Commands->Push‘, select ‘origin‘ next to ‘Remote‘. If everything went fine (it should): Congratulations! You have just made a new repository on your server and committed some files
To be honest, I don’t really like Git Extensions because the Explorer integration isn’t the best there is. There is a program called TortoiseGit which is similar to TortoiseSVN for those of you who are familiar with it. It’s not as good yet, but I will install it as well and use both Git Extensions and TortoiseGit. Happy gitting!



Nice entry. What about setting up gitosis on Windows? It is a pain in the @sss and very frustrating.
@Mike Henke
Thanks
I haven’t looked into setting Gitosis up on Windows, because my server runs Ubuntu server 9.10. I could look into it, if there isn’t much info on it on the internet.