Skip to content
Daniel Kehoe edited this page May 19, 2012 · 24 revisions

GitHub and Rails

by Daniel Kehoe

Last updated 19 May 2012

Using GitHub with Rails. If you’re creating an app for deployment into production, collaborating with others, or simply desire to roll back code changes as needed, git allows you to set up a source control repository. If you are building a throw-away app for your own education, you may decide not to set up git, but sooner or later you’ll need to learn to use it to participate in the open source community.

This is a guide for developers using the example apps from the Rails Apps repository. Others may find it helpful as well.

If you are creating a Rails application template, you can use the git recipe from the rails_apps_composer repository.

New to Git?

If you arew new to git, you can read a free online version of the book Pro Git by Scott Chacon.

Check that git is installed on your computer:

$ git version

If you need to install git, refer to the section Installing Git from Scott Chacon’s book. Also see First-Time Git Setup from the book.

Michael Hartl’s Rails Tutorial book also covers Version control with Git.

Ignore Files

When you use the rails new command, Rails creates a .gitignore file for you. You may want to modify it:

.bundle
db/*.sqlite3
log/*.log
tmp/
.DS_Store

The RailsApps project has a more extensive example .gitignore file you might want to examine.

Initialize Git For Your Rails Application

Be sure you are in your application’s root directory.

Initialize git and check in your first commit:

$ git init
$ git add .
$ git commit -m 'initial commit'

You can check your commit status at any time with:

$ git status

Save it to GitHub

Use a remote source control repository if you want an offsite copy of your work or you plan to share your work with others.

Get a free GitHub account if you don’t already have one.

Check that your GitHub account is set up properly:

$ ssh git@github.com

Go to GitHub and create a new empty repository (http://github.com/repositories/new) into which you can push your local git repo.

Add GitHub as a remote repository for your project and push your local project to the remote repository:

$ git remote add origin git@github.com:YOUR_GITHUB_ACCOUNT/YOUR_PROJECT_NAME.git
$ git push origin master

At each stage of completion, you should check your code into your local repository:

$ git commit -m "some helpful comment"

and then push it to the remote repository:

$ git push origin master
Clone this wiki locally