Setting up a Gitosis Server on OS X

I currently run a Team Foundation Server as my source control management for my Windows based projects, but I found that nigh unusable when doing anything related to Linux and Mac development; as the only way to check in is to have a shared directory on the Mac/Linux system that Visual Studio maps to a project in TFS. Rather clumsy.

Since I started working Android, I slowly became git fanboy. The GUI tools are still unbelievably primitive (as is the case with Linux in general it seems…), but the speed, flexibility, and ease of use of the command line tools and the SCM itself more than make up for that aspect. When I set up a Hackintosh last week, I also purged my computers of all Linux VMs and I forgot to take into account that I might want one running for dedicated SCM and other Linux-ish work. But, I figured, I might as well try installing gitosis and see if it works: gitosis is just a Python script that runs in an SSH session. And, it turns out it does!

These steps already assume you have git and Python installed by way of MacPorts.

As I mentioned before, gitosis is actually run in a restricted SSH session to provide the repository access, and RemoteLogin is Apple’s implementation of an SSH daemon/server. So, the first step is to make sure you have Remote Login and Remote Management enabled on OS X:

RemoteLogin

I prefer to keep my git repository in a case sensitive partition/image. I recommend you do the same, as there may be issues otherwise. But, OS X can’t be installed on a case sensitive partition, so you might need to repartition your hard drive to include a case sensitive partition:

WDC WD3000GLFS-01F8U0 Media

Now, let’s add a “git” account that will own the repository and provide repository access via SSH. This can be a standard user account. You should not run gitosis under your account, because it restricts shell access to the SSH session, limiting it to gitosis-serve. (You should also verify that the git account has remote login access in the Sharing section, although it should available by default.)

Accounts-2

Now, let’s set up gitosis. The steps are very similar to the ones found at the site I referenced. Let’s drop to a Terminal. If you do not have an SSH key yet, generate one now with ssh-keygen.

ssh-keygen

Download and install gitosis:

mkdir ~/src
cd ~/src
git clone git://eagain.net/gitosis.git
cd gitosis
sudo python setup.py install

By default, gitosis creates repositories in the ~/repositories directory of the “git” user account. And OS X by default places user HOME directories on the case-insensitive partition. Let’s create the repository directory on the case sensitive partition, and create a ~/repositories symlink to it:

sudo mkdir /Volumes/PartitionName/repositories
sudo ln -s /Volumes/PartitionName/repositories /Users/git/repositories
sudo chown git /Volumes/PartitionName/repositories
sudo chown git /Users/git/repositories

Next we need to make sure the git user has the proper directories in its PATH variable (or you may get a gitosis-serve not found error). We add them by modifying the ~/.bashrc file located at /Users/git/.bashrc:

vi /Users/git/.bashrc

Insert the following into the file:

PATH=/opt/local/bin:/usr/local/bin:$PATH

And make the owner “git”:

sudo chown git /Users/git/.bashrc

The last step is to initialize gitosis and give yourself access to it by adding your public key:

sudo -H -u git gitosis-init < ~/.ssh/id_rsa.pub

This should give you a working gitosis installation! Administration of the git repository is done by checking out the gitosis-admin repository from git, making changes to the config, and checking back in. That is incestuously cool! So, if you can check out the gitosis-admin directory, that means everything is working great:

git clone git@your-host-name:gitosis-admin.git

 

Hopefully that worked. If so, you can begin editing the gitosis.conf file to create more repositories and add users. More information about how to set up repositories and access can be found here.

4 comments:

plastiswafer said...

i found this particular post quite difficult to read and in fact when i tried to set up this "server", my house caught fire and i'm pretty sure i may have killed my neighbors.

thanks a lot

emil said...

dude wtf i read these instructions and right as i pressed the power button of this new "server", i blacked out and woke up in new delhi.. what the hell man

Alan H said...


But, OS X can’t be installed on a case sensitive partition,


Not true - unless something changed in the last week or so. You can install OS X on a case sensitive filesystem -- it just isn't the default choice.

Some applications will refuse to run. The only one that I know of at this point in time is CS3 and CS4; good old Adobe. Or is it ADoBe ?

Anonymous said...

Are you assuming all the access will be done locally? That seems a bit pointless. Otherwise shouldn't you add your remote id_rsa.pub not your local one?