I am not able to push on git?

后端 未结 6 848
傲寒
傲寒 2020-12-24 15:05

git push origin master shows an error

failed to push some refs to \'git@github.com:xyz/abc.git\' To prevent you from losin

6条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-24 15:46

    I had this too and couldn't find anywhere on StackOverflow with the following useful nugget clearly stated: Git won't let you push to a different branch if your working branch has diverged from it. There's an easy fix - just switch to the branch you want to push to and merge your working branch into it. So instead of trying this:

    git push origin master   <========== On "mybranch"
    

    Do this:

    git checkout master      <========== Switch to the branch you want to push to
    git pull origin master   <========== Get latest from remote repository
    git pull origin mybranch <========== Merge in changes from "mybranch"
    ======== Resolve any issues ========
    git push origin master   <========== Push the merged changes
    

提交回复
热议问题