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
sudoaddusergitsudopasswd-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:
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:
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-admingitadd.gitcommit-m"Add new repo, add new keys, give access"gitpush
Gitolite will create the repository and control access according to your rules.