Heroku is an excellent app hosting service that supports several frameworks. Suppose you already have an app deployed on heroku with the following address:
your_app.herokuapp.com and now you want to continue developing your app on a different machine.
Scenario 1: You hosted your source code somewhere else, say, http://www.github.com. You already pull the source code from it by doing
git clone https://github.com/username/your_project_name.git. Now, for your changes how do you push app to heroku?
If you have never used heroku on this new machine, you need to install it:
gem install heroku
Next, cd to
your_app directory and login to heroku using your credentials:
It is interesting to note that you can refer your local project to more than one remote repositories. This makes possible for you to pull from a remote repository remote and push your changes to another. Moreover, in your local project, git stores a nickname or alias of each remote repository you are referring to.
Now, in order to link your local directory to your remote repository on heroku, in your project directory run the following command:
git remote add heroku email@example.com:your_app.git
Let’s take a look at what the above line does. The
git remote is a command used to manage remote repositories. Option
add will add heroku remote repository to your local directory. The
heroku is the alias, or nickname of that remote repository. Lastly, the
firstname.lastname@example.org:your_app.git is the address of the remote repository.
After adding the remote repository, try running
This will show your remote aliases. In this case you will see
They are the nicknames of the two remote repositories that are linked to your local directory, the second one is where you first clone your code from, the first one is the one on heroku that you just add. To view details of those remote repositories, run
git remote -v
In order to push your change to heroku, simply run
git push heroku master
Scenario 2: You just clone the project directly from heroku and push there. Have read through the first scenario, the second one now pretty “abc”. After installing heroku and run
heroku login, pull the source code:
git clone email@example.com:your_app.git
Because there is now only one remote repository related to your local machine, you just need to do
git push to apply your changes.
Conclusion: This short post shows you how to use heroku connect to existing app. The key thing here is the ability of git to refer local project to as many remote repositories as you want. More reading about
git remote can be found here: http://gitref.org/remotes/. Oh by the way, don’t you notice that
heroku also uses
git for version control ? Have fun !!!!