Home   >>   Git   >>   How To Install Gitolite Having Redmine Access To Repositories
How To Install Gitolite Having Redmine Access To Repositories PDF Print E-mail
( 2 Votes )
How To - Git
Written by Christian Foronda   
Wednesday, 25 May 2011 18:57

Login to Git repository server and add git user. Execute this as root:

# yum install git

 

# useradd git
# passwd git
Changing password for user git.
New password: 
Retype new password: 
passwd: all authentication tokens updated successfully.

 

Note: ~/bin should be part of the default $PATH. In CentOS, this is already default.

 

Go back to your workstation (desktop) and create your SSH public key. If you have existing key pair, then skip this:

$ ssh-keygen
ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/chr1x2/.ssh/id_rsa): 
Created directory '/home/chr1x2/.ssh'.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/chr1x2/.ssh/id_rsa.
Your public key has been saved in /home/chr1x2/.ssh/id_rsa.pub.
The key fingerprint is:
2d:2f:df:9f:e4:0e:3c:20:79:6d:98:17:50:f0:6d:ff chr1x2@chr1x2-desktop

 

Import your public key to git repository server:

$ scp ~/.ssh/id_rsa.pub git@gitserver:chr1x2.pub

 

Get a copy of Gitolite. The rest will be done from the server:

$ git clone git://github.com/sitaramc/gitolite.git

 

If your server is behind the firewall or does not have direct connection to Internet, find a machine that has. Then clone Gitolite like this:

$ git clone git://github.com/sitaramc/gitolite.git
$ cd gitolite
$ git bundle create /tmp/gitolite.bdl -all

 

Copy /tmp/gitolite.bdl to the git repository server on the same directory. Once you copied it, go back to git repository server and execute the following:

$ git clone /tmp/gitolite.bdl gitolite

 

Install Gitolite:

$ cd gitolite
$ mkdir -p ~/bin ~/share/gitolite/conf ~/share/gitolite/hooks
$ src/gl-system-install $HOME/bin $HOME/share/gitolite/{conf,hooks}
$ cd ~
$ gl-setup chr1x2.pub
The default settings in the rc file (/home/git/.gitolite.rc) are fine for most
people but if you wish to make any changes, you can do so now.

hit enter...

 

Then the vi editor pops up; exit it by typing ":q" (colon, then the letter 'q'), and hit enter. Then the install completes:

The default settings in the rc file (/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 /home/git/repositories/gitolite-admin.git/
creating testing...
Initialized empty Git repository in /home/git/repositories/testing.git/
[master (root-commit) 6fe7e21] start
 2 files changed, 6 insertions(+), 0 deletions(-)
 create mode 100644 conf/gitolite.conf
 create mode 100644 keydir/chr1x2.pub

 

Clone the gitolite-admin repo to your workstation. Go back to your workstation then:

$ mkdir ~/projects
$ cd projects
$ git clone git@gitserver:gitolite-admin

 

Add other users as administrator:

$ cd gitolite-admin
$ vi conf/gitolite.conf

 

@admins     = otheruser chr1x2

repo        gitolite-admin
            RW+     =   @admins

repo        testing
            RW+     =   @all

 

Get the otheruser ssh public key and copy it to keydir:

$ cp /tmp/otheruser.pub keydir
$ git add .
$ git commit -m 'add otheruser as administrator'
$ git push origin master

 

Adding other users to git repository server:

$ cd gitolite-admin
$ vi conf/gitolite.conf

 

Add the following:

repo    foo
        RW      =   user1
        R       =   user2

repo    bar
        RW      =   user2
        R       =   user1

 

This will create two new repos "foo" and "bar". The "foo" repo will be writable by user1, but read-only to user2. The "bar" repo is writable by user2, read-only to user1.

$ cp /tmp/user1.pub keydir
$ cp /tmp/user2.pub keydir
$ git add .
$ git commit -m 'add user1 and user2, add repo foo and bar'
$ git push

 

Add project:

$ cd ~/projects
$ mkdir project1
$ cd project1
$ git init
Initialized empty Git repository in /home/cf/projects/project1/.git/
$ touch testfile
$ git add testfile
$ git remote add origin git@gitserver:project1
$ git add * && git commit -am "Initial commit"
[master (root-commit) aa624f4] Initial commit
 0 files changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 testfile

 

Add user to project repository:

$ cd ~/projects/gitolite-admin/
$ vi conf/gitolite.conf

 

Add the following:

repo    project1
        RW     =   chr1x2

 

Save and exit.

Update the Gitolite configuration:

$ git add conf
$ git commit -m 'add project1'
[master 389d8ea] add project1
 1 files changed, 3 insertions(+), 0 deletions(-)
$ git push
Counting objects: 7, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (4/4), 385 bytes, done.
Total 4 (delta 1), reused 0 (delta 0)
remote: creating project1...
remote: Initialized empty Git repository in /home/git/repositories/project1.git/
To git@gitserver:gitolite-admin
   1c492c1..389d8ea  master -> master

 

Go back to project1 directory and push to the repository:

$ cd -
$ git push origin master
Counting objects: 3, done.
Writing objects: 100% (3/3), 219 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
To gitolite@b8:project1
 * [new branch]      master -> master

 

Let Redmine show a gitolite-controlled repository. Go back to git repository server. Do this as root:

# mkdir /projects
# cd /projects
# git clone --mirror /home/git/repositories/project1.git
# chown -R git:git project1.git

 

Keep the repositories in sync:

# cd /home/git/repositories/project1.git/hooks
# cat >> post-receive << EOF
> #!/bin/sh
> /usr/bin/git push --mirror /projects/project1.git
> EOF
# chown git:git post-receive
# chmod 700 post-receive
# cd /projects/project1.git
# git config --add core.sharedRepository 0644

 

Add the new project to Redmine. Do the usual routine in adding new project. On the "Settings >Repository" tab:

SCM: Git
Path to .git directory *: /project/project1.git

 

Now, you can do the development on your workstation and doing the add, commit, push routine.




blog comments powered by Disqus
Last Updated on Friday, 27 May 2011 08:46