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

前端 未结 17 1272
梦如初夏
梦如初夏 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 04:54

    The error possibly comes because of the different structure of the code that you are committing and that present on GitHub. You may refer to: How to deal with "refusing to merge unrelated histories" error:

    $ git pull --allow-unrelated-histories
    $ git push -f origin master
    
    0 讨论(0)
  • 2020-11-22 04:55

    I have done below steps. finally it's working fine.

    Steps

    1) git init

    2) git status (for checking status)

    3) git add . (add all the change file (.))

    4) git commit -m "<pass your comment>"

    5) git remote add origin "<pass your project clone url>"

    6) git pull --allow-unrelated-histories "<pass your project clone url>" master

    7) git push -u "<pass your project clone url>" master

    0 讨论(0)
  • 2020-11-22 04:56

    You can try this: git pull origin master --rebase

    0 讨论(0)
  • 2020-11-22 04:56

    This is how I solved this issue:

    1. git pull origin master
    2. git push origin master

    This usually happens when your remote branch is not updated. And after this if you get an error like "Please enter a commit message" Refer to this ( For me xiaohu Wang answer worked :) )

    0 讨论(0)
  • 2020-11-22 04:57

    You can override any checks that git does by using "force push". Use this command in terminal

    git push -f origin master

    However, you will potentially ignore the existing work that is in remote - you are effectively rewriting the remote's history to be exactly like your local copy.

    0 讨论(0)
  • 2020-11-22 04:57

    Force to push

    git push -f origin master

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