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.

- 18,397
- 19
- 91
- 140

- 41,172
- 38
- 121
- 173
9 Answers
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 git@heroku.com:project.git
where 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
where, again, project
is the name of your Heroku project (thanks, Colonel Panic). You can name the Git remote anything you want by passing -r remote_name
.
[Update]
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
--app
option (e.g.heroku info --app myapp
), it will use that app. - If you specify a Git remote name via the
--remote
option (e.g.heroku info --remote production
), it will use the app associated with that Git remote. - If you specify no option and you have
heroku.remote
set in your Git config file, it will use the app associated with that remote (for example, to set the default remote to "production" usegit config heroku.remote production
in your repository, and Heroku will rungit config heroku.remote
to read the value of this setting) - If you specify no option, the gem finds no configuration in your
.git/config
file, 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
--app
to your command.

- 157,729
- 40
- 374
- 311
-
1If you try to use the `heroku git:remote` method, check that you're using the heroku toolbelt cli, and that you don't have any heroku gem still installed on your system (seems it didn't work for me with the old gems). – Pierre-Adrien Jan 11 '13 at 10:47
-
3Also, for multiple heroku branches you can use `$ git config heroku.remote
` to set default app so you can use terminal commands for that app. – Sheharyar Jul 18 '13 at 16:27 -
I had a rights error with the first method, the second did work `heroku git:remote -a project` – pansay Nov 07 '15 at 20:46
-
Is the remote url mentioned somewhere in the dashboard? I have that every time I have to add a remote manually (not through toolbelt) i have to [look up the pattern in the help](https://devcenter.heroku.com/articles/git). – Janusz Skonieczny Apr 06 '16 at 08:20
-
1if using http i.e. `heroku login` then the remote is of the form `https://git.heroku.com/project-name.git` – max pleaner Aug 11 '16 at 00:33
-
This answer should be at the top of the official Heroku page: https://devcenter.heroku.com/articles/git – Turtles Are Cute May 05 '17 at 17:20
-
Had the same problem as @pansay; simply doing `git remote add ...` can lead to error `Permission denied (publickey)`. Probably because I didn't upload my SSH key to my heroku account. If using `heroku git:remote ...` this problem does not appear (probably uses another way of identification) – Cédric Van Rompay Jan 25 '19 at 18:10
-
This helped me, so i'm sharing: `git remote add heroku git.heroku.com:project.git` ; It's a subtle difference. Notice though, in my example, there is a significant lack of an "@" symbol, compared with the first suggestion in the top answer above: `git remote add heroku git@heroku.com:project.git` – J.R. Bob Dobbs Apr 11 '20 at 00:34
-
2Note: Heroku now describes it in the project overview: Navigate to https://dashboard.heroku.com/, click your app, then switch to the "deploy" tab and choose the deployment method "Heroku git" (selected by default). Then, you'll get instructions on how to connect an existing folder/git with Heroku. – handy Apr 13 '20 at 08:30
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.
See https://devcenter.heroku.com/articles/git#creating-a-heroku-remote

- 132,665
- 89
- 401
- 465
-
1
-
2You can name the remote anything you want by passing `-r other_remote_name` – MasterScrat Feb 04 '17 at 14:35
-
2This is still the correct way to do it even if you've connected your Heroku app directly to GitHub. Note it will not overwrite your "origin" remote; it creates a "heroku" remote instead. – Seth Mar 08 '17 at 01:32
-
i am new to heroku and it is showing.. `set git remote heroku to https://git.heroku.com/my-service.git` .. what to do now?.. – Sunil Garg May 13 '22 at 05:33
Don't forget, if you are also on a machine where you haven't set up heroku before
heroku keys:add
Or you won't be able to push or pull to the repo.

- 2,388
- 1
- 18
- 22
-
4Oh yes! That helped me too. I had an app where we started basic, then bifurcated "heroku" into "staging" and "production". So I did `git remote add staging git@staging.xx:yy.git` and `git remote add production git@production.xx:yy.git` -- but that wasn't enough. When I tried to do `git push staging master` (or production) I'd get "Permission denied (publickey). fatal: The remote end hung up unexpectedly". What fixed that error was to do `heroku keys:add` as Ghoti mentions. – Purplejacket Aug 31 '11 at 19:07
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)
heroku apps
it will list the apps you have access to if you set up for the first time, you probably need to
heroku keys:add
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

- 14,438
- 7
- 79
- 77

- 191
- 1
- 5
heroku login
git init
heroku git:remote -a app-name123
then check the remote repo :
git remote -v

- 686
- 7
- 9
Use heroku's fork
Use the new "heroku fork" command! It will copy all the environment and you have to update the github repo after!
heroku fork -a sourceapp targetapp
Clone it local
git clone git@heroku.com:youamazingapp.git
Make a new repo on github and add it
git remote add origin https://github.com/yourname/your_repo.git
Push on github
git push origin master

- 817
- 11
- 13
You should probable start ssh-agent and add your keys. Check this,
It helped me.

- 10,332
- 18
- 78
- 115
I've my project in github and heroku, for upload an heroku use :
heroku git:remote -a <project>
The doc it is:

- 4,325
- 39
- 27