Link your local directory to an existing app on Heroku

Heroku is an excellent app hosting service that supports several frameworks. Suppose you already have an app deployed on heroku with the following address: and now you want to continue developing your app on a different machine.

Scenario 1: You hosted your source code somewhere else, say, You already pull the source code from it by doing git clone Now, how do you push your changes to that app on heroku?

If you have never used heroku on this new machine, you need to install it:

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 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:

Let’s take a look at what the above line does. The git remote is a command used to manage remote repositories. Option add adds a remote repository to your local directory. The heroku is the alias, or nickname of that remote repository. Lastly, the is the address of the remote repository.

After adding the remote repository, try running

READ  Cache Long in Java

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

In order to push your change to heroku, simply run

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:

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 link your local directory to an existing webapp on heroku. 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: Oh by the way, don’t you notice that heroku also uses git for version control ? Have fun !!!!

Leave a Reply

Your email address will not be published. Required fields are marked *