Use Git with a Rails Project and Push to GitHub
Follow this step by step guide to using Git in a Rails application and pushing the code to a remote repository on github.com.
Guide Tasks
  • Read Tutorial
  • Watch Guide Video
Video locked
This video is viewable to users with a Bottega Bootcamp license

Follow this step by step guide to using Git in a Rails application and pushing the code to a remote repository on github.com.

Before going into deployment, go and sign up for an account on Github. It is completely free, and you will need this account for deployment. Github is a central repository that stores all your code, so you can access it from anywhere. It is particularly useful when your machine crashes, as you have a backup of all your code on the web.

In this lesson, I've created a new application call taski with no code inside it. The idea is to show you how to push your code to Github.

In the console, when I did a ls, you can see that it just has directories and no other files or code.

large

As a first step, type the command:

git init

and this will initialize your git repository. You can see the status of your git repository with the command git status. This is how your screen should look:

large

Since this is not a Git course, we are not going to go into every line. Rather, I'm going to teach you to push your code into Github and then to Heroku.

Coming back to our application, type the command git add.

Now, if you do git status you can see all the different files that are waiting to get committed.

large

In the next step, commit your files with the command:

git ci -m "Initial commit"

You can give any name too instead of initial commit.

medium

If you run git status, no file will be listed and you'll only get a message that says there is nothing to commit.

Next, we have to create a repository on github. Go to your home page on github.com, and click on the + sign. From the drop down menu, click New repository.

large

Fill all the fields in the next page.

large

You can make your code private or public. I use the private method to store all my production files because I'm working for someone else, but I use the public option when I'm creating any open-source projects. If you go for the private option, then there is a small fee. Also, don't check the initialize this repository with a README option as this would make you do some extra work that is not needed.

After you click on the Create repository button, you should see this screen:

large

Copy the code on that screen, for my project it looks like this:

git remote add origin https://github.com/jordanhudgens/gittest.git
git push -u origin master

and paste it in your command line. It should ask for your username and password. There are also detailed instructions on how to install github on your local machine, so make sure you follow it. Once you enter your credentials, you should see this:

large

Now, when your refresh the page, you can see that all the code for our test application has been pushed into github.

large

And that's it!