This is a github cheat sheet I created after going through Michael Hartl’s excellent getting start with git tutorial as part of his also excellent online RubyOnRails book.

For a more thorough walk through go here. For a quick fix read on.

Create new git repository

Assuming you’ve installed rails, git, created a github account, and have a rails app you want to put under version control, navigate to the root of your rails app and create a new git repository as follows:

$ git init

Then create an ignore file at the root (in this case using TextMate) and add the following

$ mate .gitignore


Add your files to the repository recursively

$ git add .

Do your initial commit

$ git commit -m "Initial commit"

Create your new repository in github using the github UI.

Then push (save) your application to github.

$ git remote add origin<username>/first_app.git
$ git push origin master

There. Your repository is setup!

Branch, edit, commit, merge

Create a new branch

$ git checkout -b myChanges

Make some changes (in this case rename a file)


If you’ve made a mistake, roll it back.

$ git checkout -f

Commit the change to your branch

$ git commit -a -m "Moved the README file"

Merge with master branch

$ git checkout master
$ git merge myChanges

Then push to git server

$ git push

Deploy Heroku

For details on Heroku setup go here.

To create an instance of your app on Heroku and deploy go:

$ heroku create
$ git push heroku master

Then push, deploy, and view your app regularly with:

$ git push
$ git push heroku
$ heroku open

Voila! You’re done!

Other handy git commands

status shows you what branch you are on in case you forget

$ git status
# On branch homepage
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)

log shows you a list of your commit messages

$ git log
commit 69197e9cb7c9b3bd8b8f53bf2bfb65419027c201
Author: foo <>
Date:   Tue Sep 7 05:41:20 2010 -0600

     Initial commit

branch shows you what branch you are currently on

$ git branch
* tutorial

You can delete old two ways. The first deletes the branch after you’ve committed your changes. The second abandons the branch and ignores any changes:

$ git branch -d topic-branch
$ git branch -D topic-branch