I ever introduced seting up git server using SSH or gitosis. However, gitolite is the way to go for managing git servers if you want an lightweight authentication layer. gitolite provides many very usefull features which can control each user’s right on each branch. I set up one gitolite git server and am very happy with it. In this post, let’s look at how to set up one gitolite git server. I aim to provide a ten-minute tutorial, and hence, will make the process straightforward, just to the point and as automatic as possible: 1 variable setting, 2 commands with twice asking root password are all steps needed.
- 1 Assumptions ∞
- 2 Set up the gitolite git server ∞
- 3 Managing the gitolite git server ∞
I make some assumptions about the git server and your workstation. This should be quite common for many readers. If your environment is not like this, you need to customize the later process by yourself. Both the server and the workstation run Linux, of course. I tested on Fedora 12 and Fedora 19. The method here has minimal requirement about the Linux environment.
About your git server ∞
- Uses default ssh port (22).
- With git installed.
- Has Internet connection for cloning from github.
You have the root password to login as root.
root account is needed to create the git user on the git server. If you do not have root, you can customize the following commands by deleting the step for creating the git user. Hence, after a little bit customization, this works on any server that provides ssh, git and Internet connection, such as some shared hosting with ssh enabled.
About your workstation ∞
- You account already has a private/public key pair. If not, you can generate one by
You are using bash and you have git, ssh and scp installed on the workstation.
Set up the gitolite git server ∞
Now, let’s start to set the gitolite git server. The following steps is done in one terminal on your workstation.
Collect the information ∞
First, let’s collect some information about the git server and your workstation:
- Your git server address (
- The user (
$GIT_USER, usually git) on the git server for storing repositories.
- The username (
$ADMIN, you can use just your login username on your workstation) that you want to use as the administrator.
Your public key (
~/.ssh/id_rsa.pub) for the git repository management.
Usually, you only need to change the
$GIT_SERVER in the following commands. Run thee commands:
GIT_SERVER=example.com GIT_USER=git ADMIN=$USER ADMIN_KEY=$HOME/.ssh/id_rsa.pub
Copy your public key to the git server ∞
You will need to input the root’s password.
scp $ADMIN_KEY root@$GIT_SERVER:/tmp/$ADMIN.pub ssh root@$GIT_SERVER chmod 777 /tmp/$ADMIN.pub
Set up the gitolite environment on the git server ∞
You will need to input the root’s password.
ssh root@$GIT_SERVER "adduser $GIT_USER; su $GIT_USER -c \ \"wget https://raw.githubusercontent.com/zma/usefulscripts/master/script/install-gitolite.sh -O /tmp/install-gitolite.sh && sh /tmp/install-gitolite.sh /tmp/$ADMIN.pub\""
This command ssh to the git server as root and does the follows. First, as root, create the user for hosting git. Then, as the git user, clone the gitolite from github, install it to ~/bin/ and set up the gitolite.
If everything goes well, you will see output as follows
--2015-06-03 14:26:03-- https://raw.githubusercontent.com/zma/usefulscripts/master/script/install-gitolite.sh Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 220.127.116.11 Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|18.104.22.168|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 448 [text/plain] Saving to: ‘/tmp/install-gitolite.sh’ 0K 100% 109M=0s 2015-06-03 14:26:03 (109 MB/s) - ‘/tmp/install-gitolite.sh’ saved [448/448] Cloning into 'gitolite'... Initialized empty Git repository in /home/git/repositories/gitolite-admin.git/ Initialized empty Git repository in /home/git/repositories/testing.git/
And the gitolite git server is set up successfully.
Test the gitolite git server ∞
You can test the gitolite git server with the default testing repository provided by gitolite:
git clone $GIT_USER@$GIT_SERVER:testing
You can edit, commit and push in the testing repository. If you are not familiar with git, you can check Howto for New Git Users for some help.
Managing the gitolite git server ∞
Management of the gitolite git server is through the gitolite-admin repository, which is similar to managing gitosis git servers. You can clone the gitolite-admin repository:
git clone $GIT_USER@$GIT_SERVER:gitolite-admin
An example task ∞
To give you a brief understanding of how to manage the repositories of the gitolite git server, let’s do one task: create a new repository example-repo, add a new user alice (public key: alice.pub) and give alice read/write/delete access to the repository example-repo.
The commands to do this (replace
/path/to/alice.pub with the actual address) are as follows.
cd gitolite-admin cp /path/to/alice.pub to keydir/ echo "repo example-repo RW+ = alice " >> conf/gitolite.conf git add keydir/alice.pub git commit -a -m 'add alice; add example-repo'; git push
The new repository is created for alice. You can print out the repository address:
For more controls and rules supported by gitolite, you can check the gitolite manual.
What’s next step? The first step after setting up a git server is usually setting up email notifications: Setting Up Git Commit Email Notifications.