The best answers to the question “How to link a folder with an existing Heroku app” in the category Dev.
I have an existing Rails app on GitHub and deployed on Heroku. I’m trying to set up a new development machine and have cloned the project from my GitHub repository. However, I’m confused as to how to link this folder up to Heroku. Originally, I used the
heroku create command, but obviously I don’t want to do that this time since it will create another Heroku instance.
The Heroku CLI has an easy shortcut for this. For an app named ‘falling-wind-1624’:
$ heroku git:remote -a falling-wind-1624 Git remote heroku added.
Heroku links your projects based on the
heroku git remote (and a few other options, see the update below). To add your Heroku remote as a remote in your current repository, use the following command:
git remote add heroku [email protected]:project.git
project is the name of your Heroku project (the same as the
project.heroku.com subdomain). Once you’ve done so, you can use the
heroku xxxx commands (assuming you have the Heroku Toolbelt installed), and can push to Heroku as usual via
git push heroku master. As a shortcut, if you’re using the command line tool, you can type:
heroku git:remote -a project
project is the name of your Heroku project (thanks, Colonel Panic). You can name the Git remote anything you want by passing
As mentioned by Ben in the comments, the remote doesn’t need to be named
heroku for the gem commands to work. I checked the source, and it appears it works like this:
- If you specify an app name via the
heroku info --app myapp), it will use that app.
- If you specify a Git remote name via the
heroku info --remote production), it will use the app associated with that Git remote.
- If you specify no option and you have
heroku.remoteset in your Git config file, it will use the app associated with that remote (for example, to set the default remote to “production” use
git config heroku.remote productionin your repository, and Heroku will run
git config heroku.remoteto read the value of this setting)
- If you specify no option, the gem finds no configuration in your
.git/configfile, and the gem only finds one remote in your Git remotes that has “heroku.com” in the URL, it will use that remote.
- If none of these work, it raises an error instructing you to pass
--appto your command.
Two things to take care while setting up a new deployment System for old App
1. To check your app access to Heroku (especially the app)
it will list the apps you have access to
if you set up for the first time, you probably need to
2. Then set up your git remote
For already created Heroku app, you can easily add a remote to your local repository with the
heroku git: remote command. All you need is your Heroku app’s name:
heroku git:remote -a appName
you can also rename your remotes with the git remote rename command:
git remote rename heroku heroku-dev(you desired app name)
then You can use the git remote command to confirm that a remote been set for your app
git remote -v
Don’t forget, if you are also on a machine where you haven’t set up heroku before
Or you won’t be able to push or pull to the repo.