Setting up a new Rails app with Git

Written by Keith McDonnell. Last updated on Tuesday, January 15, 2008.

For the purposes of this tutorial I’ll assume you have a working UNIX like operating system, such as Linux or Apple Mac OS X. You can also use cygwin for windows but you really should get a better computer .

Also, a package manager (such as apt or yum) for your operating system will be invaluable if you have to install new software, otherwise you’ll have to download, compile & install from source (no thanks).

Install packages

If you haven’t already, you’ll need to install the following software (on Ubuntu 8.10):

  1. Ruby 1.8 $ sudo apt-get install -Y ruby1.8-dev ruby1.8 ri1.8 rdoc1.8 irb1.8 libreadline-ruby1.8 libruby1.8
  2. Ruby gems $ sudo apt-get install -Y rubygems1.8
  3. rails $ sudo gem install rails sqlite
  4. git $ sudo apt-get install -Y git-core

Setup a new rails app with git source control

Create a brand new rails application $ rails APP_NAME
Then Change into the root directory $ cd APP_NAME
Ensure git ignores generated files

  $ touch .gitignore
  $ touch log/.gitignore
  $ touch tmp/.gitignore

Add these files to .gitignore


Add all files $ git add ., and then commit $ git commit -m "Starting new app"

Congratulations! You’re now good to go with git & rails.

Optionally, you can freeze your version of rails: Use rake rails:freeze:gems to use the latest version of rails in your gem repository OR you can use a specific release with rake rails:freeze:edge RELEASE=1.2.0

All your work thusfar has been saved on your computer. So how do you share your work with others? You’ll have to create a shared repository. You can store your shared repository on a server and access it via SSH or use a hosted service such as github or unfuddle .

A day in the life of a rails git project


If you'd like to discuss this article, you can send me an email and/or publish an article online and link back to this page.