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)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…