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

Maintenance

Migrate Repo to Different Server

https://gitolite.com/gitolite/install.html#moving-servers

Backup / Restore

if you f$$$your repos / server, do the following:

* create git user
* update sshd_config
* restore /home/git to the original location
* su - git
* chown git:git .* *
* gitolite setup --hooks-only
* if not sucessful, gitolite setup (https://stackoverflow.com/questions/38632852/git-smart-http-r-any-denied-by-fallthru)

Switch from Master to Main on Gitolite

as the Name Master should not be used anymore, let’s switch to main. New Repo’s will be built with “Main” …

ssh root@yourserver
doas su - git
git config --global init.defaultBranch main

Rename existing Repos

quite tricky …

git branch -a
git checkout master
git checkout -b main
git push -u origin main
#git remote set-head origin main
git push origin :master
git branch -D master

/box-easyrsa$ git branch -a 
* main
  remotes/origin/HEAD -> origin/main
  remotes/origin/main
  remotes/origin/master

-> "git push origin :master" not working

git push origin :master 
remote: error: By default, deleting the current branch is denied, because the next
remote: 'git clone' won't result in any file checked out, causing confusion.
remote: 
remote: You can set 'receive.denyDeleteCurrent' configuration variable to
remote: 'warn' or 'ignore' in the remote repository to allow deleting the
remote: current branch, with or without a warning message.
remote: 
remote: To squelch this message, you can set it to 'refuse'.
remote: error: refusing to delete the current branch: refs/heads/master
To git.noflow.ch:box-easyrsa
 ! [remote rejected] master (deletion of the current branch prohibited)
error: failed to push some refs to 'git.xxxxxx.xx:xxx-easyrsa'

## on the Gitolite Server ##
git@gitoliteserver $ git config --global receive.denyDeleteCurrent warn
git@gitoliteserver $ sed -i 's/master/main/' xxx-easyrsa.git/HEAD 

## try again ##
git push origin :master
git branch -D master

## Foreign Repos
git branch --set-upstream-to=origin/main main

and done !

sha256: d3ee45af0ff780d7c859eddd0f342d3726d8fbbc65b4cb4f09a66ca2ac5c0e7d