-1

I did some changes on my local server and I want to push it to my master repository. This usually works fine but this time I get an error message:

Pushing to https://mypage.com/project.git To https://bitbucket.org/mypage/project.git ! [rejected] master -> master (fetch first) error: failed to push some refs to 'https://mypage.com/project.git' hint: Updates were rejected because the remote contains work that you do hint: not have locally. This is usually caused by another repository pushing hint: to the same ref. You may want to first integrate the remote changes hint: (e.g., 'git pull ...') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details. Completed with errors, see above

peace_love
  • 6,229
  • 11
  • 69
  • 157

1 Answers1

3

This happens if the remote is changed. Is some else working on your project as well? Or do you have any build-scripts that might affect master?

Use git stash to save your local changes. pull down the changes from the remote with git pull and then use git stash pop to get back your work. Now you can continue normally with git commit and git push

You can also use git push --force if you are 100% sure that the work you have local contains the changes needed, but be careful with this one since it will override any changes on the remote.

Mr.Turtle
  • 2,950
  • 6
  • 28
  • 46
  • Yes, I am working on another imac also on the project. But right now I only worked on my laptop. So I do not want old stuff from the imac, I just want everything from my laptop to the master – peace_love Dec 04 '18 at 07:06
  • Thank you for your advice. I am so afraid that all my local work will be overwritten – peace_love Dec 04 '18 at 07:07
  • 1
    If I understand you correctly you want to override everything that is in master with what you have on your laptop, right? If you want everything that is on your laptop exactly how it is right now in master, use `git push --force` This will force your push and ignore that there are weird differences. – Mr.Turtle Dec 04 '18 at 07:12
  • Yes exaclty! Ok, I will test it now! Thank you – peace_love Dec 04 '18 at 07:13
  • 1
    Everything worked fine! Thank you! – peace_love Dec 04 '18 at 07:20