Git, Heroku, and GitHub

About

Git is the preferred version control package for the Ruby on Rails community. Installing Git is a prerequisite for deploying your application to Heroku and storing the source code on GitHub.

Prerequisites

Ruby on Rails and Git need to be properly installed in Linux. The Rails version should be 3.0.9.

Start Your Project

  1. Begin your application with the "rails new (appname)" command and then cd your way into your new application's root directory.
  2. Update the Gemfile. Open the Gemfile in your application's root directory and replace the line beginning with "gem 'sqlite3'" with "gem 'sqlite3', '1.3.3'".
  3. To implement the new setup indicated by the Gemfile, enter the command "bundle install".
  4. From your application's root directory, enter the command "rails server -d" to start your local web server.
  5. After starting up your local web server, wait a few seconds and then open your web browser to the URL http://localhost:3000 . You should see the Ruby on Rails "Welcome aboard!" page.

Set Up Git

  1. Enter the following commands (with the appropriate substitutions) to configure Git:
    git config --global user.name "Your Name"
    git config --global user.email youremail@example.com
  2. To start using Git on your project, cd your way into its root directory and enter the command "git init". To add all of your project files (except the ones specified in the .gitignore file) to the Git repository and commit the changes, enter the following commands:
    git add .
    git commit -m "(Your comments here)"
  3. To see a list of your commits, enter the command "git log". Note that each commit has its own checksum value. To revert back to an earlier commit, enter the command "git reset --hard (checksum value)".

Set Up Heroku

Once you have Git properly set up, you can start deploying your application to Heroku.
  1. If you have not already done so, sign up for a Heroku account.
  2. From the root directory of your application, enter the command "sudo gem install heroku" to install Heroku.
  3. Once you have installed Heroku, enter "heroku keys:add" to store your Heroku login information so you can access your account.
  4. Enter the command "heroku create" to obtain space for your application.
  5. To upload your application to Heroku, enter "git push heroku master".
  6. To view your application on Heroku, enter the command "heroku open". Your browser should display the Ruby on Rails "Welcome aboard!" page.
  7. OPTIONAL: To rename your application on Heroku (from the default name it gave you when you entered "heroku create"), enter the command "heroku rename (your appname)". Your new application name CANNOT be the same as that of an existing application already deployed on Heroku.

Set Up GitHub

Once you have properly deployed your new app to Heroku, you'll want to save your source code to GitHub.
  1. If you haven't already done so, create an account for yourself on GitHub.
  2. Enter the command "mkdir ~/.ssh/github". You'll need this directory for saving your GitHub SSH keys, which MUST be separate from your Heroku SSH keys.
  3. Go to the GitHub Help Page and follow the instructions on how to set up GitHub (starting with adding your SSH keys).
  4. Go to the GitHub Help Page and follow the instructions on how to create a new repository on GitHub. Give the repository the same name as that of your application. After you have created the depot, you will see a list of commands to enter. Since you have already completed most of the tasks, the only ones left are the line beginning with "git remote add" and the line beginning with "git push".
  5. When it's time to save and upload your source code changes to GitHub, the commands are:
    git add .
    git commit -m "(Insert comments here.)"
    git push origin master

Updating Heroku and GitHub

  1. To update Git, enter the following commands:
    git add .
    git commit -m "(Insert comments here.)"
  2. To update Heroku, enter "git push heroku master".
  3. Make sure the deployment server uses the same version of Ruby as you are in your local environment. The default stack on Heroku is bamboo-mri-1.9.2, which uses Ruby 1.9.2. To see the list of available stacks on Heroku, enter "heroku stack". To switch to the bamboo-ree-1.8.7 stack (which uses Ruby 1.8.7), enter the command "heroku stack:migrate bamboo-ree-1.8.7".
  4. Every rake function you performed locally to make the application work must be repeated on the deployment server. Enter "heroku (rake command)" to do this. Examples include "heroku rake db:migrate" and "heroku rake db:seed".