26

I have repository (lets say A) and forked repository A-dev on Bitbucket. Everything had been worked good for 3 months. But recently, when I tried to create pull request in A-dev it says:

Unable to merge
Unrelated branches

Why this would happen and how it can be solved? How can I troubleshoot it?

Edit

the screenshot of the error

halfer
  • 19,824
  • 17
  • 99
  • 186
user2257338
  • 417
  • 1
  • 5
  • 11
  • Could you post a screenshot of that error message? Where do you see it? (in the Web GUI? in the Atlassian Stash Git client?) – VonC Apr 08 '13 at 12:11
  • Yes, provide more information. My guess from above limited information is that your A-dev branch is changed over the time. You need to rebase your fork in that case. – chhantyal Jul 19 '13 at 13:42
  • What are the exact Git commands you're using and the messages you're getting in return? If you update your question with more detailed information, it'll be easier to help out with this :) – leifericf Jul 30 '13 at 21:22

4 Answers4

12

That means there would be merge conflicts if it attempted to merge. You have to merge in "Repo A" and resolve the conflicts. Then push back up to BitBucket so it can close the pull request. Example workflow:

git remote add repo_a https://url.com/path/to/repo
git fetch repo_a
git merge repo_a/dev
# resolve conflicts
git commit -am "Merge in repo_a/dev and resolved conflicts"
git push origin dev

If you've never dealt with merge conflicts in Git, checkout this SO question.

Community
  • 1
  • 1
Sam
  • 20,096
  • 2
  • 45
  • 71
12

This was my solution:

git checkout branchA
git pull origin branchB --allow-unrelated-histories

...and resolve merge conflicts.

A. Sa.
  • 221
  • 3
  • 9
7

Try a:

git rebase origin/[BRANCH-NAME]
1

I experienced this same issue when working on a new copy of an existing application.

I got the new copy of the existing application as a zip file and then unzipped it into a new folder.

And then I just copied some contents of the old copy of the existing application to the directory of the new copy of the existing application.

Afterwhich, I deleted the old copy of the existing application, and then I tried to push the new copy of the existing application to the remote repository of the existing application on Bitbucket.

And then it threw the error:

Unable to merge 
Unrelated branches

Here's how I solved it:

The issue was that I did not copy the .git directory of the old copy of the existing application into the new copy. The git directory stores information about the remote source repository. This information was lost when I trashed the old copy of the existing application.

All I had to do was to restore the old copy of the existing application from my Trash bin, and then I copied the .git directory into the new copy of the existing application.

This time I tried to push to the remote source repository of the existing application and it worked amazingly fine.

Another workaround will be to do a fresh git clone of the existing application from the remote repository and then copy the .git directory from it into the new copy of the existing application. Afterwhich, I can then push back to the remote repository.

That's all.

I hope this helps

Promise Preston
  • 24,334
  • 12
  • 145
  • 143