Gitolite

Page content

You wanna host your own Git Repositories ? Have a look at Gitolite. It does all for you :)

Install GitoLite

pkg_add gitolite

Add git user

root@gitserver ~# adduser -silent
Enter username []: git
Enter full name []: git repo user
Enter shell bash csh git-shell ksh nologin sh [ksh]:
Uid [1001]:
Login group git [git]:
Login group is ``git''. Invite git into other groups: guest no
[no]:
Login class authpf bgpd daemon default pbuild staff unbound
[default]:
Enter password []:
Disable password logins for the user? (y/n) [n]: y

Name:        git
Password:    ****
Fullname:    git repo user
Uid:         1001
Gid:         1001 (git)
Groups:      git
Login Class: default
HOME:        /home/git
Shell:       /bin/ksh
OK? (y/n) [y]: y
Added user ``git''
Add another user? (y/n) [y]: n

Basic Setup

Setup Repo, add your key

su - git

echo "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIIv1QwiWujY3x8F6TUe5iDy6syr8avQUw1rtinpiD0zb stoege-key" > mykey.pub

gitolite setup -pk mykey.pub
#Initialized empty Git repository in /home/git/repositories/gitolite-admin.git/
#Initialized empty Git repository in /home/git/repositories/testing.git/

Client

Check if Git Repo is accessible

git ls-remote git@server:gitolite-admin
fe4e13fe5e70fc15d2ffdfb5700a5c0f2b36eb69        HEAD
fe4e13fe5e70fc15d2ffdfb5700a5c0f2b36eb69        refs/heads/master

Checkout Admin Repo

stoege@gitclient ~$ git clone git@server:gitolite-admin
Cloning into 'gitolite-admin'...
remote: Enumerating objects: 6, done.
remote: Counting objects: 100% (6/6), done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 6 (delta 0), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (6/6), done.

stoege@gitclient ~$ ls
gitolite-admin

Admin Tasks

Add Client (ssh Key)

cd gitolite-admin
git pull

echo "ssh-ed25519 AAAAxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx user1-key" > keydir/user1.key
git add .
git commit -m "add Key User1"

echo "ssh-ed25519 AAAAxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx user2-key" > keydir/user2.key
git add .
git commit -m "add Key User2"

git push

Add Repo & Permission

add Repo “myrepo” and Permission to gitolite.conf

stoege@gitclient ..lite-admin$ cat conf/gitolite.conf
repo gitolite-admin
    RW+     =   mykey

repo testing
    RW+     =   @all

repo myrepo
    R       =   @all
    RW      =   user1

git add .
git commit -m "neues repo 'myrepo' erstellt"
git push

stoege@gitclient ..lite-admin$ git push
Enumerating objects: 7, done.
Counting objects: 100% (7/7), done.
Delta compression using up to 2 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (4/4), 373 bytes | 373.00 KiB/s, done.
Total 4 (delta 1), reused 0 (delta 0), pack-reused 0
remote: Initialized empty Git repository in /home/git/repositories/myrepo.git/
To puffy202:gitolite-admin
   12bd4b7..28cab17  master -> master

SSH Config on GIT Server

gitolite restricts the user automatically so :)

git@gitserver ~$ cat .ssh/authorized_keys
# gitolite start
command="/usr/local/libexec/gitolite/gitolite-shell mykey",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty ssh-ed25519 AAAAC...npiD0zb stoege-key
# gitolite end

Rename Git Repo

On the Git Server

su - git
repositories
mv git_repo_old.git git_repo_new.git

cd /where-ever-this-is/gitolite-admin/
edit conf/gitolite.conf -> rename repo from git_repo_old git_repo_new
git add/commit/push

sha256: d3ee45af0ff780d7c859eddd0f342d3726d8fbbc65b4cb4f09a66ca2ac5c0e7d