git push rejected

后端 未结 8 2085
無奈伤痛
無奈伤痛 2020-12-22 23:50

I give up! Whenever I try to push I get a stupid:

! [rejected]        master -> master (non-fast forward)
error: failed to push some refs to \'git@github         


        
8条回答
  •  死守一世寂寞
    2020-12-23 00:21

    Jarret Hardie is correct. Or, first merge your changes back into master and then try the push. By default, git push pushes all branches that have names that match on the remote -- and no others. So those are your two choices -- either specify it explicitly like Jarret said or merge back to a common branch and then push.

    There's been talk about this on the Git mail list and it's clear that this behavior is not about to change anytime soon -- many developers rely on this behavior in their workflows.

    Edit/Clarification

    Assuming your upstreammaster branch is ready to push then you could do this:

    1. Pull in any changes from the upstream.

      $ git pull upstream master

    2. Switch to my local master branch

      $ git checkout master

    3. Merge changes in from upstreammaster

      $ git merge upstreammaster

    4. Push my changes up

      $ git push upstream

    Another thing that you may want to do before pushing is to rebase your changes against upstream/master so that your commits are all together. You can either do that as a separate step between #1 and #2 above (git rebase upstream/master) or you can do it as part of your pull (git pull --rebase upstream master)

提交回复
热议问题