Why use GitHub when you can have your own? Hehe. Gitosis is a nice way of having your very own private repository. And it’s free! It just takes a while to set it up.

Deploying Rails to Centos 5

You should have Apache, mySQL, rails andย Passenger installed by now. And of course, you will need to have Git installed as well. You could actually install Gitosis in another remote server but for me, Gitosis resides in the same remote server that I have been working in. To get Gitosis to work, you need to install Python as Gitosis is written in it. [shell] yum install python-setuptools[/shell]

When you are done, get out to the root of your server and clone gitosis [shell]git clone git://eagain.net/gitosis.git[/shell]
Now go into the directory and run the installer. [shell]cd gitostis
python setup.py install[/shell]

When gitosis is installed you can safely delete the gitosis folder by running[shell] rm -rf gitosis[/shell]

Now you need to set up a shell user to access Gitosis. [shell]adduser –shell /bin/sh \
–group \
–disabled-password \
–home /home/git \
When you are done, you should have a /home/git folder ready for your repositories to reside in.

You already know that to git clone or push you have to roughly do a [shell]git clone git@yourdomain.com:reponame.git[/shell]To have this setup you need to provide Gitosis your SSH key from your local computer.

So in your local computer’s terminal.[shell] local $ ssh-keygen -t rsa[/shell] However, if you already have an id_rsa.pub generated before you can actually skip this step and use your existing one instead.

Either way, once you have an id_rsa.pub file in your ~/.ssh folder run this command to copy it to your remote server[shell]local $ scp $HOME/.ssh/id_rsa.pub user@[/shell]

If you run into an error you can manually copy the text in id_rsa.pub file and make the exact same file in /home/git by [shell]remote $ vim id_rsa.pub[/shell] Paste in the text you copied from your local file.

Once you are done, you are ready to initialize Gitosis. [shell]remote $ su git
remote $ -H -u git gitosis-init < id_rsa.pub [/shell] It should initialize and reinitialize a git repo. Now you can remove the id_rsa.pub in your remote computer.

Now do some permissions changing.[shell]remote $
chmod 755 /home/git/repositories/gitosis-admin.git/hooks/post-update
chmod 755 /home/git
chmod 700 /home/git/.ssh
chmod 644 /home/git/.ssh/authorized_keys

Back to your local computer’s terminal, head to an empty folder and clone the gitosis-admin files. [shell] local $ git clone git@yourdomain.com:gitosis-admin.git[/shell]
If you couldn’t get past cuz of ssh or there is no git repo in that location. You need to change your local computer’s ssh config file.
Mine was in /private/etc/ssh_config. You can google to find the location of your ssh config file in your OS. Add this two lines in to make it automagically work [shell]Host yourdomain.com
Port 1234[/shell]
Replay with your remote server’s ServerName.com and the SSH port.

When you are able to clone, head into the local gitosis-admin directory either through terminal or by navigating there in Finder. Open up gitosis.conf and add the following lines:
[shell][group reponame]
writable = reponame
members = copy-from-gitosis-admin-chunk-above[/shell]

Back to your local terminal, you can now do some cool things to push the changes you did back to your remote server. Hehe.[shell]local $ git commit -a -m “Allow my local have write access to remote”
git push[/shell]

Now if you check your remote server’s gitosis.conf file you will be pleased to see that it is updated. ๐Ÿ™‚

The last thing to do here is to initialize a git setup in your local development app. [shell]git init
git remote add origin git@yourdomain.com:reponame.git
git add . # add whole project
git commit -m “Initial code for myblog”
git push origin master:refs/heads/master[/shell]
With this you will have your latest branch of your development app pushed to your very own Gitosis server, ready to deploy with Capistrano.

Note : If you want to be able to push from your remote app back to your Gitosis, you can generate the id_rsa.pub key from your remote server and place the file in the gitosis-admin/keydir directory. Update your gitosis.conf and you should have access to the project.

Next : Capistrano