60

I currently have the latest version of my code on another computer that I want to develop from (Home computer and laptop for when I'm out and about) I set up heroku for my app on my laptop. Now I need to associate my code on my desktop so that I can push to heroku from there as well.

This is what I get from my desktop:

desktop:~/NetBeansProjects/onlinescheduler$ git pull heroku master
fatal: 'heroku' does not appear to be a git repository
fatal: The remote end hung up unexpectedly

I can't do heroku create because that will create a separate app. How do I associated the existing code with (or pull down a brand new version from) heroku?

Whats the command to do this?

aarona
  • 35,986
  • 41
  • 138
  • 186

5 Answers5

113

Also, If you've never used heroku before on the other machine, you'll need to do a few more things first:

$ gem install heroku
$ heroku login
 [then enter your credentials] 
$ heroku keys:add [path to keyfile]

Now you can clone the remote repository:

$ git clone git@heroku.com:<heroku_app>.git <local_directory>
Gayle
  • 3,053
  • 3
  • 20
  • 13
  • 1
    this gives me an "! Internal server error" when adding the local key (a different one from that on my other machine). Any ideas? – elgrego Nov 27 '11 at 18:36
  • 4
    I think this is the more correct way to do this: https://devcenter.heroku.com/articles/clone-heroku-app – StackExchange User Feb 21 '13 at 15:18
  • Very helpful. Note that the keys command is by default not needed: https://devcenter.heroku.com/articles/keys – J0ANMM May 16 '18 at 12:23
  • Heroku CLI not needed. I added my public key in heroku user setting using web browser and then cloned it using: git clone git@heroku.com:.git – midlan Jan 24 '20 at 15:24
51

First of all, you'll want to follow the Quick Start instructions for Heroku, which you can get straight from the horse's mouth, right here: https://devcenter.heroku.com/articles/quickstart

Once you've gotten through step 3, come back here.

Then, you can type this into the command line: heroku git:clone -a myapp

This is described here: https://devcenter.heroku.com/articles/git-clone-heroku-app

Then, if you want to grab the database too, here are some options. Newer Heroku instructions on import/export: https://devcenter.heroku.com/articles/heroku-postgres-import-export

Older heroku instructions on push and pull: https://blog.heroku.com/archives/2009/3/18/push_and_pull_databases_to_and_from_heroku

If you are using mongo, this is a useful tool to sync your mongo database: https://github.com/pedro/heroku-mongo-sync#readme

ogoldberg
  • 781
  • 7
  • 8
  • On import/export Note also the heroku pgbackups:transfer command is very usefull `$ heroku pgbackups:transfer --help ` `Usage: heroku pgbackups:transfer [SOURCE DATABASE] DESTINATION DATABASE` `$ heroku pgbackups:transfer green teal --app example` – Jonathon Batson Jun 10 '14 at 22:08
  • @JonathonBatson Hi there can we clone others existing apps? – Shift 'n Tab Jul 12 '17 at 12:03
  • @ShiftN'Tab you can find app cloning instructions here: https://devcenter.heroku.com/articles/git-clone-heroku-app The command is `heroku git:clone -a myapp` – ogoldberg Jul 12 '17 at 15:49
  • 1
    @ogoldberg hi thanks for your response i already know how to do it, but this means anyone can clone your app? how do we make it private? – Shift 'n Tab Jul 13 '17 at 04:50
5

If you first need to get the app from Heroku, clone your app.

To do that, write in your Terminal:

heroku git:clone -a your_app_name

If you already have the app and the remote to heroku follow the next steps. If not, you can check instructions here https://devcenter.heroku.com/articles/git

  1. Find the name of your database

Write in your Terminal:

heroku pg:info -a your_app_name

it will look something like this:

HEROKU_POSTGRESQL_MAROON_URL
  1. Find the name of your local database

In your Rails app go to config/database.yml

it will look something like this:

your_app_name_development
  1. Clone your production database (PostgreSQL)

Write in your Terminal with your own database names:

heroku pg:pull HEROKU_POSTGRESQL_MAROON_URL your_app_name_development -a your_app_name

HEROKU_POSTGRESQL_MAROON_URL is an example of how could be the name of your production database (in Heroku): my_app_name_development is the name of your development database (locally) the_name_of_my_app is the name of your app in Heroku

Don't forget to finish this with bundle install...

drjorgepolanco
  • 7,479
  • 5
  • 46
  • 47
  • `HEROKU_POSTGRESQL_MAROON_URL` wont work for most people as their url bash variable could be different. Suggest editing your post so that the command is more generic. – aarona Jun 01 '15 at 23:07
  • Yes, it says "it will look something like this" But, Thanks anyways for your suggestion! I updated it to be more specific. – drjorgepolanco Jun 02 '15 at 02:33
3

If you already have your code base ready and have heroku setup, use:

$ heroku git:remote -a your_heroku_app

This will allow you to deploy from your new location. Reference: https://devcenter.heroku.com/articles/git#creating-a-heroku-remote

0

Once you create a key in a new computer, you have to upload your new SSH key by typing heroku keys:add.

Marko
  • 20,385
  • 13
  • 48
  • 64
Sebas
  • 9
  • 1