Created a remote code repository on bitbucket. Then, following this instruction, I add a local repository to the bitbucket:

$ git init $ git add . $ git commit -m 'initial commit of full repository' $ git remote add origin git@bitbucket.org:username/perl.git $ git push -u origin --all 

Here is the message:

To bitbucket.org:username/perl.git
! [rejected] master -> master (fetch first)
error: unable to send some links to "git@bitbucket.org: username / perl.git"
hint: Updates were rejected because the external repository contains
hint: changes that you do not have in your local repository.
hint: Usually, this is due to the fact that someone has already sent changes to
hint: same place. Before resubmitting your changes, you need to
hint: pick up and merge changes from external repository to yourself
hint: (for example, using "git pull ...").
hint: For more information, see "Note about fast-forwards"
hint: in "git push --help".

Okay. The git pull origin master command writes the following:

warning: no common commits
remote: Counting objects: 3, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), ready.
From bitbucket.org:username/perl
* branch master -> FETCH_HEAD
* [new branch] master -> origin / master
fatal: failure to merge unrelated change histories

I used to use both Git and Bitbucket before, but for the first time I have such problems. In general, I do not understand what kind of nonsense.

  • run git fetch; git log --oneline --decorate --graph --all; git fetch; git log --oneline --decorate --graph --all; , add the output of this command to the question ( edit ). - Nick Volynkin

2 answers 2

There are already commits in the remote repository. There are several options for how to solve this issue.

  1. The commits in the remote repository are needed: git pull , after merge - git push
  2. The commits in the remote repository are NOT needed (for example, an empty readme is added there): git push --force . I do not recommend doing this if the history of commits is already there.
  • The commits in the remote repository were really not needed. So just deleted the one deleted and created a new one. With new everything works. Thanks for the help - SweetHorror

In vain they marked as the correct answer from @dekanszn

It breaks rather than fixes: git pull simply cannot be done due to the error described in the question. And not everyone wants to delete changes.

It is solved like this:

  1. git pull origin master --allow-unrelated-histories
  2. Then we solve conflicts
  3. Then commit & push