23 January 2009 ~ Comments Off

Setting Your Git Up

Whilst building this blog, I was also trying out git to manage my solutions to Project Euler and host them on github. Consequently when I got bored of solving Euler’s problems, using git for version control for this thing seemed to be the next logical step.

I had read about making a Capistrano recipe to checkout the latest version of code hosted on github to be used in deploying your app and I thought this would be the “right way” to go about doing things, so that’s what I set out to do.

It didn’t take long before I made what your currently looking at. I was quite pleased with what I’d done upto this point so I went away and got a new domain/cheap rails hosting plan from media72 as I’d heard good things about them. I also took them up on the free peepcode screencast which sweetened the deal.

Upto this point, I’d been checking my code into a local git repository but I hadn’t yet pushed it onto github. This was before I realised that I’d have to upload my database.yml file with my username and password intact for my database to connect with rails, once checked out.

CRAP!

I graduated with a Masters in Computer Security but it don’t take a genius to know that this is all bad. For those of you who haven’t caught on by now, all projects on github are publicly accessible.

That’s when I realised this is what the private git repo’s are for on their site; something intruiged me till I realised they weren’t free. $7 a month…not a chance!

Just to point out, this is an easy fix for anyone with a brain, but it turns out mines so small I can hear it rattle when I have to brake hard at a set of traffic lights. I should have ftp’d the complete datababase.yml file to the Shared file that Capistrano creates, and include a command to copy this file into every deploy of my checked out rails app.

But no I always go the hard way, which actually didn’t turn out to be that hard though it was a fun learning experience. I stumbled across this article which was the answer to all my problems.

It basically means I can host my own git repository privately on my shared hosting plan, using the following set of commands.

1
2
3
4
ssh username@yourcheaphost.com
mkdir -p ~/git/yourproject.git
cd ~/git/yourproject.git
git --bare init

Once this was setup, I had to change my local project to push to my private repository.

1
git remote add origin ssh://username@yourcheaphost.com/~/git/yourproject.git

The final thing I had to do was to add this to the .git/config file in my local project.

1
2
3
  [branch "master"]
    remote = origin
    merge = refs/heads/master

That was me sorted! Now I can push code to my private repo, without having to change my Capistrano recipe at all. Once again massive props to John Nunemaker. This experience also makes me wonder why there are numerous services which offer private repository for money. If anyone knows why, or knows of an easier way to about doing this, feel free to comment.

Comments are closed.

SEO Powered by Platinum SEO from Techblissonline