Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BitBucket - error: failed to push some refs

I have some projects I would like to upload on my bitbucket private profile. I performed the following steps but I get an error.

  1. Convert my project to git with: git init

  2. Next:

git add
git commit -m "some message"
  1. I created a bitbucket repository and version control system is GIT.

  2. I then type this (of course with real account name and reponame and repo owner):

git remote add origin https://<repo_owner>@bitbucket.org/<accountname>/<reponame>.git
  1. Finally,
git push -u origin master

I did all of this and my terminal gives me this error:

To https://bitbucket.org/milosdev_me/lfs.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://[email protected]/milosdev_me/lfs.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.
like image 863
Milos Avatar asked Nov 28 '22 02:11

Milos


2 Answers

Try:

git push origin master --force

This works for me.

like image 158
Alfredo Morales Avatar answered Dec 09 '22 09:12

Alfredo Morales


Your master branch has some code that you don't locally have, and to prevent you from conflicts, it doesn't let you to push further changes, before you have them locally. To resolve this, pull all the changes to your local repository (your project):

git pull origin master --allow-unrelated-histories

After that, you will have all the code that is available on your master branch.

NOTE: Be careful, pulling the code from remote branch might mess up all the changes locally. Make sure to save those changes somewhere, or create another branch locally where you will pull your origin master branch, so it doesn't mess up your changes.

like image 40
zlatan Avatar answered Dec 09 '22 09:12

zlatan