git: updates were rejected because the remote contains work that you do not have locally

前端 未结 17 1200
梦如初夏
梦如初夏 2020-11-22 04:54

I\'m working on a team with a few developers using git on BitBucket. We are all working on a dev branch, not pushing to master until a release.

相关标签:
17条回答
  • 2020-11-22 05:13

    git pull --rebase origin master

    git push origin master


    git push -f origin master

    Warning git push -f origin master

    • forcefully pushes on existing repository and also delete previous repositories so if you don`t need previous versions than this might be helpful
    0 讨论(0)
  • 2020-11-22 05:14

    It happens when we are trying to push to remote repository but has created a new file on remote which has not been pulled yet, let say Readme. In that case as the error says

    git rejects the update

    as we have not taken updated remote in our local environment. So Take pull first from remote

    git pull
    

    It will update your local repository and add a new Readme file. Then Push updated changes to remote

    git push origin master
    
    0 讨论(0)
  • 2020-11-22 05:17

    git pull <remote> master:dev will fetch the remote/master branch and merge it into your local/dev branch.

    git pull <remote> dev will fetch the remote/dev branch, and merge it into your current branch.

    I think you said the conflicting commit is on remote/dev, so that is the branch you probably intended to fetch and merge.

    In that case, you weren't actually merging the conflict into your local branch, which is sort of weird since you said you saw the incorrect code in your working copy. You might want to check what is going on in remote/master.

    0 讨论(0)
  • 2020-11-22 05:18

    I fixed it, I'm not exactly sure what I did. I tried simply pushing and pulling using:

    git pull <remote> dev instead of git pull <remote> master:dev

    Hope this helps out someone if they are having the same issue.

    0 讨论(0)
  • 2020-11-22 05:18

    I had this error and it was because there was an update on the server but SourceTree was not showing any updates available (possibly because I was offline when it last checked). So I did a refresh in source tree and now it shows 2 items to push instead of 1 item.

    So be sure to press refresh or pull if you get this error and then try again.

    0 讨论(0)
提交回复
热议问题