Deploy Rails App to Heroku(Part 2)

In this section we’ll initialize our git repository locally & will connect it to Github.

In root directory of your application run this command

git init

This will initialize empty git repository.

Empty git repository is initialized

Now run git status command in your terminal

git status

It will look like this

It shows untracked files

The best part it‘s telling you what to do next. It says use

git add <file name>

to add all untracked files but if you use above method you can add files one by one like

git add db
git add config

What if you want to add all file in oneshot you can do that use

git add .

Above command will add all the untracked file. Run git status again after running git add command

git status

It will look like below

After using git add command all untracked files are now tracked but you have to commit it to save it into your local

Run git commit command to save it to your local also you have to write a message also inside the quotes to state what you have done in this commit

git commit -m "Created rails app"

It will look like

Everything is saved in your local now after running git commit command

Now if you run git status

git status

you’ll get

Showing nothing to commit every thing is saved

Now go to you github account then go to repositories section & click on new .Fill the information whatever it is asking for like repository name & so on. Here is mine

Click on create repository once you are done

Then it will look something like this

Your new repository has been created

Click on clone or download once

This url is to add this remote repository to your local so that you can push your changes. If you use https every time you are pushing something you have to enter your email and password else you can clone ssh url, then you don’t need to enter your email and password everytime. I’ll use ssh one

Copy that url & in your terminal use git add remote origin command to add that remote repository.

git remote add origin

You have to use git push origin master to push your code to master branch on github repo you created .

git push origin master
Everything is pushed to master branch of you repository you created

Now go to your repository on github & refresh on you’ll get something like this

So congrats finally you have pushed your code to github. In the next section will see how to use heroku to deploy code that we have on github repository.

Happy coding :)

In case if you haven’t read first part here is the link

Deploy Rails App to Heroku(Part 1) here