Setup Git Server (gitolite)

This setup using SSH connection for transfer instead of SVN’s http (webdav).

The gitolite use a default user (e.g. git) to establish a ssh connection, and wrap multiple users management with rsa pub key.

# generate your key if you don't have one
# (use default answers and choose a passphase)
ssh-keygen -v -t rsa -C username@hostname

# transfer the pub key to git server
scp ~/.ssh/id_rsa.pub username@server:username.pub

# add git user that gitolite will run as
# (questions doesnt matter much just remember the password)
sudo adduser git

# let user git own the pub key and move it to git's home
sudo mv username.pub ~git/username.pub
sudo chown git:git ~git/username.pub

# log in as git
su - git

# generate key for user git with no passphase
ssh-keygen -v -t rsa

# get the content of the key and keep it in clipboard for later
cat ~/.ssh/id_rsa.pub

# install gitolite from github
# update: can also sudo apt-get install gitolite
cd /home/git
git clone git://github.com/sitaramc/gitolite gitolite-source
cd gitolite-source
mkdir -p ~/bin ~/share/gitolite/conf ~/share/gitolite/hooks
/home/git/gitolite-source/src/gl-system-install ~/bin ~/share/gitolite/conf ~/share/gitolite/hooks
cd /home/git
/home/git/bin/gl-setup username.pub
rm -f username.pub

# administration of gitolite
# this is done via checking out a copy of the gitolite-admin from server
# and modify its /conf/gitolite.conf file and then push them back after commit locally first
# check out (clone) a copy of gitolite-admin
git clone git@servername:gitolite-admin

# modify conf/gitolite.conf
vim conf/gitolite.conf

# for example to add a new repository
# gitolite.conf content
repo    projectname
        RW+        = username

# and now commit then push back up to create the new repo for projectname
git add -A
git commit -m "add new project repo"
git push

# you can then create a new git (or skip this if using an existing one)
mkdir projectname
cd projectname
git init

# also set up basic stuff like user.name and user.email
git config --global user.name "Vincent Lu"
git config --global user.email vincent.lu@email.com

# now add the new git repo on server as a remote server for the current git local
git remote add origin git@servername:projectname.git
git push origin master

# you can track the remote by adding:
git config branch.master.remote servername
git config branch.master.merge refs/heads/master

# if run into memory issue on server or local, reduce memory usage by:
git config core.packedGitWindowSize 16m
git config core.packedGitLimit 64m
git config pack.windowMemory 64m
git config pack.packSizeLimit 64m
git config pack.thread 1
git config pack.deltaCacheSize 1m

# to add new users
# add access to gitolite-admin/conf/gitolite.conf
repo pluto RW+ = someone
# add key to gitolite-admin/keydir
ssh-keygen -v -t rsa -C someone@hostname
cp ~/.ssh/id_rsa.pub gitolite-admin/keydir/someone.pub
# push change back to server
cd gitolite-admin/
git commit -a -m "add new user someone"
git push

Leave a Reply