How to link a folder with an existing Heroku app

GitHeroku

Git Problem Overview


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.

Git Solutions


Solution 1 - Git

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:

  1. If you specify an app name via the --app option (e.g. heroku info --app myapp), it will use that app.
  2. 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.
  3. 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" use git config heroku.remote production in your repository, and Heroku will run git config heroku.remote to read the value of this setting)
  4. 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.
  5. If none of these work, it raises an error instructing you to pass --app to your command.

Solution 2 - Git

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

Solution 3 - Git

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.

Solution 4 - Git

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

Solution 5 - Git

heroku login 

git init

heroku git:remote -a app-name123

then check the remote repo :

git remote -v

Solution 6 - Git

Use heroku's fork

  1. 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
    
  2. Clone it local

     git clone git@heroku.com:youamazingapp.git
    
  3. Make a new repo on github and add it

     git remote add origin https://github.com/yourname/your_repo.git
    
  4. Push on github

     git push origin master
    

Solution 7 - Git

You should probable start ssh-agent and add your keys. Check this,

http://wordgraphs.com/post/5000/Heroku--Permission-denied--publickey---fatal--Could-not-read-from-remote-repository-

It helped me.

Solution 8 - Git

I've my project in github and heroku, for upload an heroku use :

heroku git:remote -a <project>

The doc it is:

https://devcenter.heroku.com/articles/git

Solution 9 - Git

for existing repository

type in terminal

$ heroku git:remote -a example

enter image description here

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionKevin PangView Question on Stackoverflow
Solution 1 - GitMichelle TilleyView Answer on Stackoverflow
Solution 2 - GitColonel PanicView Answer on Stackoverflow
Solution 3 - GitGhotiView Answer on Stackoverflow
Solution 4 - GitRohit SurekaView Answer on Stackoverflow
Solution 5 - GitWael ChorfanView Answer on Stackoverflow
Solution 6 - GitmsrootView Answer on Stackoverflow
Solution 7 - GitStrangerView Answer on Stackoverflow
Solution 8 - GitDiego Santa Cruz MendezúView Answer on Stackoverflow
Solution 9 - GitMecaTheclauView Answer on Stackoverflow