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
By doing
git push heroku mybranch:master
, you are telling git to take your localmybranch
branch and merge it with the remotemaster
branch (remotely stored on your heroku repo).You get an error because
master
is ahead ofmybranch
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 updatedmaster
by committing some other code. If you were to merge backmybranch
intomaster
, you would risk causing conflicts between your code and the new code contained inmaster
, thus Git refuses to do the merge. First, you have to update your local branch with the new version ofmaster
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 themaster
branch locally). What you should do to avoid things likegit push heroku mybranch:master
is, when you finish working on a branch, always merge your changes tomaster
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)
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.