要做新项目了,老大要先做一个原型,但不能污染公司的主代码仓库,于是大家决定用目前最流行的Git。Google了一下,目前Linux下最好的Git服务器搭建工具就是Gitolite。在这总结归纳一下方法。我用的平台是Ubuntu 12.04.
Step 1. Add Group “git” and User “git”
1 2 3 |
sudo groupadd git sudo useradd -d /home/git -m -g git -s /bin/bash git sudo passwd git |
Step 2. Install gitolite
Switch user “git” first
1 |
su - git |
Get gitolite from github first
1 |
git clone git://github.com/sitaramc/gitoline.git |
Make a “bin” directory where gitolite will be installed into.
1 |
mkdir bin |
Install gitolite to bin
1 |
gitolite/install -to ~/bin |
Step 3. Setup gitolite
Before we setup gitolite, you need to get the administer’s ssh public key file.
As we know, when we call “ssh-keygen” on our workstation, we can get a private key (don’t share it to others) and a public key. Gitolite need the public one. For more details, please read gitolite-doc.
1 2 3 4 5 6 7 8 9 |
[jasonlee@myWorkstation .ssh]$ ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (/Users/jasonlee/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /Users/jasonlee/.ssh/id_rsa. Your public key has been saved in /Users/jasonlee/.ssh/id_rsa.pub. ... [jasonlee@myWorkstation .ssh]$ scp id_rsa.pub git@gitolite_server:/tmp/jasonlee.pub |
As I showed to you, I copy the public key to gitolite_server:/tmp/jasonlee.pub. Next we setup the gitolite and configure the admin’s public key.
1 |
bin/gitolite setup -pk /tmp/jasonlee.pub |
Then you will find there are some files and folders generated.
Step 4. Add a new repo and a user.
As a admin, if you want to manage repos and users, you need to clone a special repo “gitolite-admin” first.
Now, jasonlee is the admin. Let’s clone that repo on my workstation first.
1 |
git clone git@gitlite_server:gitolite-admin |
Then you can find two folders conf and keydir.
In folder conf, there is gitolite’s configuration file gitolite.conf. Default, it likes
1 2 3 4 5 |
repo gitolite-admin RW+ = jason repo testing RW+ = @all |
keydir is the folder to put the public key files of users.
If you want to add a user jason and a new repo foo.
You need put jason.pub to keydir first and add following lines in gitolite.conf.
1 2 |
repo foo RW+ = jason |
Then commit and push all changes to gitolite server.
OK, everything is done! Repo foo is ready for jason now. 🙂