Suppose you want to manage private Git repositories for a project, team, or company.
Hosted services such as GitHub , Bitbucket , and GitLab are convenient. But if, like me, you're a bit of a control freak, you may prefer a simpler way to administer private repositories while keeping your source code under your control.
Gitolite is small, simple, and powerful. User access control and repository creation are only a git commit and git push away.
This guide shows you how to set up private Git infrastructure with Gitolite and easily manage repositories and users.
First, log in to the remote machine where you want to set up Gitolite:
commandShell command
sshgit-server
Install Git:
commandShell command
sudoaptinstallgit
Create a dedicated user to manage the repositories and enforce the access-control rules, then disable password access for that user:
commandShell command
sudoaddusergit
sudopasswd-lgit
On your local machine, open a new terminal and copy your public key to the remote machine:
commandShell command
scp~/.ssh/id_rsa.pubgit-server:
If the copy succeeds, id_rsa.pub will be in the remote yolo user's home directory.
The adduser command created /home/git. Now create its .ssh directory, move the public key to /home/git/.ssh/yolo.pub, and set the directory's permissions and ownership:
commandShell command
sudomkdir-p/home/git/.ssh
sudomv~/id_rsa.pub/home/git/.ssh/yolo.pub
sudochmod700/home/git/.ssh
sudochown-Rgit:git/home/git/
Switch to the git user, then clone and install Gitolite:
Log out of and back into the git user's shell so the commands installed in ~/bin become available. Then set up Gitolite with yolo.pub as the administrator key:
commandShell command
exit
sudosugit-l
gitolitesetup-pk~/.ssh/yolo.pub
exit
exit
Leave the git user's shell and the remote machine. You need to run exit twice because you are two levels deep (yolo -> git).
Debian note
If the scripts in ~/bin aren't picked up automatically, you might need to create a ~/.bash_profile file and add ~/bin to $PATH:
Bash
exportPATH=$PATH:~/bin
Ubuntu picks up the scripts in ~/bin automatically.
Now clone the gitolite-admin administration repository:
Get the public keys from users who need Git access and place them in ~/gitolite-admin/keydir. Name each key after its user, such as tom.pub and jerry.pub, because you will use these names when configuring access.
To create a repository named yolo-project, give yourself full access, and grant tom and jerry read-write access, add these lines to ~/gitolite-admin/conf/gitolite.conf:
~/gitolite-admin/conf/gitolite.conf
repo yolo-project
RW+ = yolo
RW = tom jerry
Then commit and push the changes to the remote gitolite-admin repository:
commandShell command
cd~/gitolite-admin
gitadd.
gitcommit-m"Add new repo, add new keys, give access"
gitpush
Gitolite will create the repository and control access according to your rules.