How to deal with "refusing to merge unrelated histories" error

Thanks it worked for me

Yes it worked…!! Thanks a ton :slight_smile:

Well you can try and do 

make the local repository recognize the remote

git remote add orign <giturl>

git branch --set-upstream-to=origin/master 

#sync the branches

git rebase

if any conflict resolve and continue

push to remote

git push


this work for me…

git clone <Repo>

git pull --allow-unrelated-histories origin master

git push -u origin master

and it works


Worked perfectly in VS Code

I got into this problem following a guide book that started with a local git repo and then tried to show how to go remote with a github account.  Left out was all the .ssh key stuff and this.  Thanks.  This answer worked for me, is much cleaner and doesn’t seem to be leaving me open to the problem versioning is supposed to prevent against.

if you already did a pull and you came up with master and origin/master but can’t merge them, the following command can help you:

git merge origin/master --allow-unrelated-histories 

its working thanks man 

Yeah, it worked for me.

Its not working when I run the command on git bash.

$ git pull --allow-unrelated-histories
Result:  fatal: not a git repository (or any of the parent directories): .git

Someone please make this answer show up at the top of the thread lol! It fixed the problem for me and the current top positioned comment is completely the incorrect practice for solving the issue. Thanks again for correct pull to stop the unrelated histories error.

Thank you xvrtzn for the solution. You are amazing. I was having this issue from days but you helped right away. Thanks much!

this doesn’t work either and git just sends you round and round in circles:

$ git pull --allow-unrelated-histories
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.

git pull <remote> <branch>

If you wish to set tracking information for this branch you can do so with:

git branch --set-upstream-to=<remote>/<branch> master

This was the correct solution for me. I’d initialised a repo locally, then created a fresh one on github to push it to. 

git pull origin master&nbsp;--allow-unrelated-histories



this was pretty much what was needed in my case.

Working for me, thanks

works for me too. More specifically something like this 

git pull --allow-unrelated-histories

works fine for me ! thanks

@xvrtzn Thanks man. It worked for me! 

git push origin master --allow-unrelated-histories

will work