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?
In fact, all you need to do to merge unrelated branches is to use the flag --allow-unrelated-histories . This tells Git to combine all the files and commits of both unrelated branches into one branch, as long as there are no file conflicts.
The alternative (and longer) way of fixing the fatal: refusing to merge unrelated histories issues is to unstage your current commits, stash them, clone your required remote repository, and then place your stashed branch contents into the new clone.
The “fatal: refusing to merge unrelated histories” Git error occurs when two unrelated projects are merged (i.e., projects that are not aware of each other's existence and have mismatching commit histories). Consider the following two cases that throw this error: You have cloned a project and, somehow, the .
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With