Git is the most hyped version control system at the moment and has been for some time now, but there is a reason for that. It’s fast, flexible, distributed (no network required), can communicate with Subversion, supports best development practices and the list goes on. We recommend using Git.
This guide shows how to install and setup a Git Repository Server using Gitolite on Linux Ubuntu 10.04 and 11.04 Server and how to access the Server from a Linux client.
This setup has been tested on both Linux Ubuntu 10.04 and 11.04, and should also work on other Debian based distributions. It also includes how to setup a config file for multiple SSH key logins.
Git is… a free & open source, distributed version control system designed to handle everything from small to very large projects with speed and efficiency.
What is Gitolite? Gitolite lets you use a single user on a server to host many git repositories and provide access to many developers, without having to give them real userids on or shell access to the server.
Install Gitolite Repository Server
Start on your Server and create the gitolite admin account git. This is the account used to access all repositories from all clients:
Create SSH keys for the git account
Go back to your local machine and open the bash to create the SSH keys for the git admin account.
Note!: In this example we specified git as the user which means that there should be two files the private key named git and the public key named git.pub.
Copy your public key to the Server.
Use scp to copy the public key to the Server. This key is used when we install the Gitolite Server.
Login on the Server
SSH to the Server with the git account or another and then change the user to root. It is good practice to have deactivated root access to the Server!
Install the Git on the Server
Start by installing Git on the Server by using the following command in the bash:
Change to git user
When we setup Gitolite we do as the gitolite admin user account git.
Download gitolite to your home directory by cloning it. This is done by the following command. The “gitolite-source” is the name given to the folder.
Here is what you should see:
in /home/git/gitolite-source/.git/ remote:
Counting objects: 3984, done. remote:
Compressing objects: 100% (1614/1614),
done. remote: Total 3984 (delta 2737),
reused 3405 (delta 2322) Receiving objects:
100% (3984/3984), 1.01 MiB | 752 KiB/s, done.
Resolving deltas: 100% (2737/2737), done.
Installation is done by several bash scripts which mean that they might not be registered in your PATH. If the bash can’t find the command gl-setup script, be sure to add it to your PATH in your bash profile (.profile). In some cases you just have to change the user, since the $PATH include is loaded on user login. In the following commands we set the current directory to gitolite-source, create directories for Gitolite, run the bash scripts and in the end setup Gitolite with the public key created earlier on.
~/gitolite-source $ mkdir -p ~/bin ~/share/gitolite/conf ~/share/gitolite/hooks
~/gitolite-source $ src/gl-system-install ~/bin ~/share/gitolite/conf ~/share/gitolite/hooks
~/gitolite-source $ cd ~
~$ gl-setup git.pub
You should see the following output and the setup opens the gitolite configuration. Don’t change anything here if you don’t know what you are doing just hit :q and enter to exit.
(/home/git/.gitolite.rc) are fine for most
people but if you wish to make any changes,
you can do so now.
hit enter... creating gitolite-admin...
Initialized empty Git repository in
creating testing... Initialized empty Git repository in
/home/git/repositories/testing.git/ [master (root-commit) 028c1b6]
start 2 files changed, 6 insertions(+), 0 deletions(-)
create mode 100644 conf/gitolite.conf create mode 100644
Remove the public key
Since we don’t want the public key laying around, we remove it from the home directory:
Setup SSH to only use public and private keys (Optional, but recommended)
This is done in the sshd_config file in /etc/ssh/sshd_config. Start by creating a backup and then open sshd_config file:
~ $ nano /etc/ssh/sshd_config
Note!: Be sure to have a fall-back plan, so you don’t lock your self out! And remember to add the defaultuser to log in to your Server.
Here are the values to set. Defaultuser is the user you log in with SSH:
AllowUsers git defaultuser
If you want learn more about how to setup OpenSSH Server using keys you can read this: How to use Putty or MSysGit on Windows to login securely on Linux via OpenSSH with public and private key pairs
Apply the SSH settings
We need to reload the SSH Server before the settings are applied. This is done by the following command:
How to use multiple SSH keys with different accounts
If you have different accounts and need mutiple SSH key logins you can specify which private keys to use. This i done by creating a config file in your $HOME/.ssh directory. Here is an example:
Administering the Gitolite Repository Server is done by cloning the admin repository, editing the configuration files and then pushing the changes to the Server. This is always done on the client!
Clone the admin repo:
Now we have the gitolite-admin repository where we can add users and new repositories. Let’s start by adding a new user and then a new repository.
Here is an example on how to add a new user and a new repo.
First make the user create a public key and have them send it to you. Add the key to the gitolite-admin keydir: ~/gitolite-admin/keydir/new_repo_user.pub
Edit the gitolite configuration file ~/gitolite-admin/conf/gitolite.conf and add the new user to the new repository reponame:
RW+ = git
RW+ = @all
RW+ = new_repo_user
First add and commit the new changes. Then push the changes to the Server:
~$ git commit -m "updated configuration"
~$ git push
Create Git repository
Now that we have created a new user and repository. We need to initialize a new project as a Git repository.
# initialize project
~$ git init
# add all files
~$ git add -A
Commit and push the changes to the Server
~$ git commit -m "Added files files to reponame"
# tell the repository where it should push changes
~$ git remote add origin git@hostname:reponame.git
# push the changes
~$ git push origin master
This is it. We recommend reading this article if you are just getting started with Git: A List of Useful & Common Git Commands Explained [Developer]
Visit the official site for lots of documentation: http://git-scm.com/
We recommend reading the documentation found on the official page: