简体   繁体   中英

Can't push master branch to Heroku in Git

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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM