Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
373 views
in Technique[技术] by (71.8m points)

ruby on rails - code push to heroku not working

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...