1

I am collaborating on a project and cloned the repo from Github, made some changes and pushed to Heroku. Now the cloned app had all of its keys and passwords hardcoded, not in ENV variables.

So I created ENV variables, added the file to .gitignore. So this app still has these keys in the commit history. What I have done now is have the author create a new repo on Github, remove .git file from original app and push new code to new repo.

So now I have cloned the new app, added a new remote the the Heroku app.

heroku git:remote -a myapplication

My issue is I cannot push the new app to the existing Heroku app. When I do I get:

error: failed to push some refs to 'git@heroku.com:myapplication.git
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')
hint: before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

So a git pull says everything is up to date.

git remote -v outputs

heroku  git@heroku.com:myapplication.git (fetch)
heroku  git@heroku.com:myapplication.git (push)
origin  git@github.com:author/myapplication.git (fetch)
origin  git@github.com:author/myapplication.git (push)

What can I do to push the new application to the existing heroku app?

Update

I ran

git push -f heroku master

which pushed but I had error

   you have not declared a Ruby version in your Gemfile.
   To set your Ruby version add this line to your Gemfile:"
   ruby '1.9.2'"

I've never had to specify before, and now all the original config vars that where set are no longer stored in Heroku.

halfer
  • 19,824
  • 17
  • 99
  • 186
Richlewis
  • 15,070
  • 37
  • 122
  • 283

2 Answers2

3

git pull would pull by default from GitHub, which has all your commits already.

You might need to:

  • git pull heroku
  • clean-up the files (if the merge brings back the hardcoded values)
  • push to origin
  • push to heroku through the heroku command.
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • thank you for your answer, would you mind looking at my update and advise if i can still do the same please? – Richlewis Jul 02 '13 at 20:20
  • @Richlewis I wouldn't have force pushed to heroku directly: the all point of pulling first is to make the push easier (without any force option). And a push to heroku should happen through an heroku command, not directly through git. If you have access to the heroku server, you could try and reset to the git repo previous state (as in http://stackoverflow.com/a/135614/6309) – VonC Jul 02 '13 at 20:23
  • ok so ive rolled back and the app is fine, im worried about pulling from heroku as it still has the original codebase on there, ie theres a hell of a lot of changes and that would cause major conflicts – Richlewis Jul 02 '13 at 20:30
1

Git uses the concept of tracked branch to know which remote branch is linked to a local branch.

In your case, you probably have your local branch (I suppose it's master) linked to origin/master. So, when you do a git pull, Git is trying to get new stuff from git@github.com:author/myapplication.git, which is not the wanted behavior.

You have to change your tracked branch using :

  • git branch --set-upstream-to heroku/my_branch

Then, you can do a git pull which will now have the wanted behavior. Then just push to heroku, as you always do.

Guillaume Darmont
  • 5,002
  • 1
  • 23
  • 35