code push to heroku not working

2019-01-12 11:41发布

问题:

I want to push code on heroku that is on gihub

I used the following command

git push heroku mybranch:master

The error is

To https://github.com/user/lyricle-new.git
 ! [rejected]        lyricle-frt-backend -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/user/app.git'
hint: Updates were rejected because a pushed branch tip is behind its remote
hint: counterpart. Check out this branch and merge the remote changes
hint: (e.g. 'git pull') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

Used the command git pull as mentioned in hint the response was Already up-to-date.

What could be the reasons behind this error? and is this the correct way to push on heroku

回答1:

By doing git push heroku mybranch:master, you are telling git to take your local mybranch branch and merge it with the remote master branch (remotely stored on your heroku repo).
You get an error because master is ahead of mybranch in terms of commits.

Consider this example:
master: --------b---------m---------
mybranch:........\-c--c--/...........

At some point, you branch (b) master into mybranch, commit (c) some code to the branch, and merge (m) it back to master.

Now consider this example:
master: --c-----b---c-----m---c--
mybranch:........\-c--c---/.......

It is pretty much the same scenario but while you were committing code to mybranch, someone updated master by committing some other code. If you were to merge back mybranch into master, you would risk causing conflicts between your code and the new code contained in master, thus Git refuses to do the merge. First, you have to update your local branch with the new version of master and then only Git will allow you to push.

In short:
- git pull heroku master:mybranch
- resolve potential conflicts
- commit modified files
- git push heroku mybranch:master


Now about Heroku, you are supposed to always push code like this: git push heroku master (considering you are on the master branch locally). What you should do to avoid things like git push heroku mybranch:master is, when you finish working on a branch, always merge your changes to master and then (after verifying that everything is working) push master to heroku.

See this resource for a simple git workflow that seem to be what you are looking for: https://www.atlassian.com/git/workflows#!workflow-feature-branch

Everything is centralized in master eventually, and you can then regularly push master to heroku (ideally you would push once for every version of your app)



回答2:

From the hints it seems that you have not pushed your latest changes to your remote repository.if you have done a pull and pushed again maybe you have removed files in your local repository that you did not remove in your remote repository.try doing a git add --all and then commit and push the changes.