4

I have a rails app hosted on heroku and i want to push the code to github(Aready created a repo on there).I tried to follow the steps in this question .Since i already have a local repository and currently can push and pull from heroku i skipped step 2 and 3 .But when i do step 4

git remote add origin git@github.com:sparkz19/stark-journey-1727.git  

It says

fatal: remote origin already exists.

And when i do git remote -v It says

    origin  git@heroku.com:stark-journey-1727.git (fetch)

    origin  git@heroku.com:stark-journey-1727.git (push)

What do i need to do here?Thank you in advance.

Community
  • 1
  • 1
katie
  • 2,921
  • 8
  • 34
  • 51

2 Answers2

2

Just give your new remote a different name than origin and you'll be good to go.

John Colby
  • 22,169
  • 4
  • 57
  • 69
2

Git complains because origin is already defined. If you still want to keep the heroku remote you could use git remote rename to save it as another remote:

git remote rename origin heroku

Reset the url with git remote set-url:

git remote set-url origin git@github.com:sparkz19/stark-journey-1727.git

Now you can push and pull to any you like:

git pull heroku master
git push origin master
rtn
  • 127,556
  • 20
  • 111
  • 121
  • i still want to be able to push and pull from heroku though .What will the first command actually do? – katie Apr 23 '12 at 21:48
  • No, the first command will overwrite current origin url (heroku) with the url to github. Do both. Rewrote my answer a bit to simplify. – rtn Apr 23 '12 at 21:53
  • In that case i wont be able to pull and push from heroku? – katie Apr 23 '12 at 21:55
  • Thank you.But now it wont let me push to git `Merge the remote changes (e.g. 'git pull') before pushing again`and i am afraid to pull because it might override my project.What do i do here? – katie Apr 23 '12 at 22:21
  • Not sure what you mean. Add it as a new question instead so we can go through it properly. – rtn Apr 23 '12 at 22:35