Git is a version control system. The creator of Linux created Git (the letter g is supposed to be pronounced as the "g" in the word "get" or "guy") because he hates CVS, and he does not like like SVN, either ( http://en.wikipedia.org/wiki/Git_(software) ).
A lot of people seem to like Git. Probably as many as those who like Linux:-). So since I am developing in Java for a FreeBSD system (Mac OS X server), I figure that I would give Git a try.
Like everything else related to Linux, Git is a little confusing. To start, is the "g" pronouced like "the "g" in "get", or is it like the "g" in "gif"? The answer is always simple when you find out, but it always takes two steps.
Git itself does not offer a server. For a version control system, that is a little unusual. If you know how bad SourceSafe is, you would probably start to wonder: is this going to be as bad as SourceSafe. The answer is no. Actually there are a few Git remote repository applications available, such as Gitolite.
There are several version of Gitolite. The latest version is version 3. To continue the tradition of keeping people confused, the different versions must be installed differently. What I describe here are applicable to version 3. It does not apply to early versions, and it will most likely not applicable to future versions.
To install Gitolite, you must first install Git. This part is surprisingly easy. You go to http://git-scm.com/download/mac, and download a .dmg file. You then open the .dmg file, and then click on the .pkg file inside to complete the installation.
Only if the whole process is that easy.
Of course not. To install Gitolite, you need to create a user account. Gitolite will monoplize this user account to act like a server. You probably want to name this user account with the user name "git" since that is what it will be used for. Ideally you would want to set it up in such a way that it does not accept actual login for OS shell access, but during the setup process, I find it much easier logged in as "git".
Step 1. From the home directory of "git" I ran
git clone git://github.com/sitaramc/gitolite
This actually copies Gitolite into git's home directory under "gitolite". To complete the initalization, you would run
sudo ./gitolite/install -ln /usr/local/bin
This creates a file called ".gitolite.rc", a directory called ".gitolite", and a directory called "repositories". The first two are hidden since they start with "." in their names. A constantly used "gitolite.conf" file is in the hidden directory .gitolite under "conf".
Even though the command used here is called "install", I would say it can only qualify as an initializor, not an installer.
Step 2. Create a repository. Open up .gitolite/conf/gitolite.conf, and add a section for your new repository:
repo MyRepository
RW+ = user1
R = user2
...
Here the user names "user1" and "user2" are not users with system accounts. They are just users that you want to give access to the repository.
At this point you do not actually have a repository yet. The official Gitolite instruction says that you must pull the default "gitolite-admin" repository, change it to "MyRepository", and add it back. It turns out that you can run "gitolite setup" to create the empty repository. It seems to know that this is necessary since "MyRepository" is listed in gitolite.conf, but the directory does not exist under "repositories", or if it is empty if you create it yourself there.
Step 3. Setting up users. Even though you would have listed a bunch of users in the "gitolite.conf" file for your repository, they do not yet have access to the repository. In fact, you would wonder: how would these users login into the server?
It turns out that they all login under the user account "git". To differentiate these different users after they login, each would store a different public key in the .ssh directory of "git". So you can run the following command to create the keys needed for each user of "MyRepository":
ssh-keygen -t rsa
When prompted for a file name, you would enter a user name for "MyRepository". You will then need to distribute the private key file to the user. For example, if the the file name is "user1", you would give it to user1.
After each key pair is created, you would run the "setup" command to update the ".ssh/authorized_keys" file automatically:
gitolite setup -pk .ssh/user1.pub
At this point, user1 can connect to the the repository via ssh.
Step 4. Configure your Git client to access the repository. I use NetBeans. When prompted for user name, you would enter "git" since that is what we used for the user account. So the URL is
ssh://git@myserver.name/MyRepository
You would then enter a file path to the private key generated earlier. This key is what actually tell Gitolite who you really are. If you used a pass phrase while generating the keys, you would enter it here as well.
Step 5. Test your connection. I used PuTTY. The key generated from ssh-keygen needs to be converted with puttygen.exe first before it can be used. The file puttygen.exe is a separate download from PuTTY. Once I connected, I got a bunch of errors. It turned out that the default shell used by Mac OS X server does not have the right paths. So I added a .bashrc file that contained a single line:
export PATH=$PATH:/usr/local/git/bin
This fixed the problem.
Thursday, June 14, 2012
Subscribe to:
Posts (Atom)