1

I have a project on my local which I want to share on Bitbucket. I created a repository on Bitbucket named "rest-api".
Now, I am into my IntelliJ IDEA IDE, and already added the project to git. I also added the project to the remote repository using IDEA.

Now, I am trying to push my project to remote, but that giving me error:

error: failed to push some refs to 'https://my@bitbucket.org/my/rest-api.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
To https://bitbucket.org/my/rest-api.git
!   refs/heads/master:refs/heads/master [rejected] (non-fast-forward)
Done
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

I read some SO questions and learned that I need to first git pull. So I tried that as well, but that also gave me the error:

Git Pull Failed
From https://bitbucket.org/my/rest-api
* branch            master     -> FETCH_HEAD
= [up to date]      master     -> origin/master
refusing to merge unrelated histories

pull window

What am I doing wrong?

The Coder
  • 3,447
  • 7
  • 46
  • 81

1 Answers1

1

This is typical of two repositories created concurrently: one locally, one remote.

Their respective master branches have no common history.

A git pull origin master --allow-unrelated-histories would allow for the two branch to merge.

If you have only one master branch and want to preserve a linear history, a git pull --rebase is fine too, and will replay your local commits on top of origin/master.

If you had a more complex local history, then git pull --rebase=merges would be needed to use the new rebase --rebase-merges option, preserving your local merges.


1) I don't want to push it to the master branch, but to a remote dev branch?

  • The pull does not change.
  • The push becomes git push -u origin dev

2) Do I need to follow this for every project I create locally and then want to push to remote?

Only if you have created the remote repo with one or several files as part of its "initialization" (README, LICENSE, CONTRIBUTION, ...).
If you create a remote repo truly empty, then you won't have this "trouble".

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Two questions here: 1) I don't want to push it to the master branch, but to a remote `dev` branch? 2) Do I need to follow this for every project I create locally and then want to push to remote? – The Coder Jul 06 '19 at 04:54
  • @TheCoder I have edited the answer to address your comments/questions. – VonC Jul 06 '19 at 05:06