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/

# 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 ~git/
sudo chown git:git ~git/

# 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/

# install gitolite from github
# update: can also sudo apt-get install gitolite
cd /home/git
git clone git:// 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
rm -f

# 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 and
git config --global "Vincent Lu"
git config --global

# 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/ gitolite-admin/keydir/
# push change back to server
cd gitolite-admin/
git commit -a -m "add new user someone"
git push

Leave a Reply