I have been fiddling around with git lately. Git is a Source Code Management and Version Control System, VCS in short, which is fast and very efficient and what sets it apart from other VCS’s is the fact that it stores snapshots of information unlike other VCS’s, which keep difference between the latest updated information and old information and you don’t need to have a connection to the git repository all the time to commit any changes, you can commit the changes locally and at a later time when you are connected to the repository, you can push the changes that you committed earlier. If you want to learn more about Git, I would suggest that you check out Git’s official website and read this book. You can also check out this very cool tutorial by the same guys. Gitolite simply eases the hosting and management tasks for repositories.
For me, the confusing part was where (server or client machine) to run which command, so I’m gonna lay down everything as clearly as I can. To install git and gitolite on your server, type:
sudo apt-get install git gitolite
This will install git and gitolite on your system but gitolite wouldn’t be set up at this time so you’ll get something like this in the output
Setting up git (1:220.127.116.11-1) ...
Setting up gitolite (2.2-1) ...
No adminkey given - not setting up gitolite.
Next, you have to generate ssh-key pair for the user on client machine, if you don’t already have one. This client machine can be a different system or the same system as the server. To generate ssh-keypair, type:
ssh-keygen -t rsa
Or you can use -N switch with ssh-keygen to provide passphrase and -f to provide its location. To generate keypair without any passphrase and its name as id_rsa and id_rsa.pub in ~/.ssh directory, type:
ssh-keygen -N "" -f ~/.ssh/id_rsa
Since, both my client and server are the same machine, I’ll just copy the public key, id_rsa.pub, to /tmp.
cp ~/.ssh/id_rsa.pub /tmp
If your server and clients happen to be different, then create a file with .pub extension in /tmp directory and paste the contents of the user’s public key into this file. We’ll be using this file later.
Now, add a user to access gitolite with
sudo adduser \
--shell /bin/bash \
--gecos 'gitolite user' \
--home /home/git \
Now, login as this user
sudo su git
Set the PATH variable for this user
echo "PATH=$HOME/bin:$PATH" > ~/.bashrc
.bashrc or logout/login for the changes to take effect. To source .bashrc, first go to the home directory and then type:
cd; source .bashrc
Now, all we need to do is setup gitolite. Remember the public key that we copied to /tmp, now, we need to use that
It will prompt you to edit gitolite.rc file, but default settings are just fine.
Once gitolite is setup, it will create a file projects.list and a directory named repositories with two more directories gitolite-admin.git and testing.git.
Gitolite will be managed by gitolite-admin directory but not directly; user, whose public key you provided in the gitolite setup, will have to clone gitolite-admin directory and changes are to be made to this cloned directory and then pushed. For cloning the directory, type:
git clone git@<hostname>:gitolite-admin
git clone git@<ip>:gitolite-admin
Now, everything will be done in the cloned gitolite-admin directory.
To add a new user, get the user’s public key. Create a file with .pub extension in gitolite-admin/keydir/ and paste the contents of the new user’s public key to this file. Then do a git add, commit and then push the changes. You can read more about it here.
To add a repository, you have to edit gitolite.conf file located at gitolite-admin/conf/ directory. Add the project along with atleast one user. The repository doesn’t have to be present, gitolite will automatically create and initialize an empty git repository. Make an entry like this
RW+ = id_rsa
R = windowuser
id_rsa and windowuser are name of the files in gitolite-admin/keydir directory without the pub.
After making the changes, again do a git add, commit and push. You can read more about it here.
If you have added a user and it asks for a password then there must be something wrong with your configuration.
If you want to see your access rights to different projects, simply type:
ssh git@<hostname> info
This is it for now.