In my local, I made new text file -> git add newfile.txt -> commit -> pull origin master -> ERROR!
"refusing to merge unrelated histories".
What is unrelated histories? , what is related histories?
When somehow the local .git
subdirectory is lost, the whole project seems to be appeared from nowhere, as all the local changes histories were contained by .git
. Thus, your local changes become unrelated. That is why all the changes are called unrelated histories
then.
In this situation, git merge or pull
request will unable to track where you made changes to add with the remote project. Hence, " refusing to merge unrelated histories"
- error occurs.
In this situation, if you try to force merge by following commands,
git pull origin master --allow-unrelated-histories
git merge origin origin/master
it will create a lot of conflicts, as it is not able to find the history of your local changes.
I ran into a similar problem where I brought in a branch from a second remote and wanted to merge with a branch from the first remote. This is different from the existing answers as I'm not using --allow-unrelated-histories on the pull, but on the merge.
git checkout master
git merge --allow-unrelated-histories myfunnybrancy
I got this issue when renaming one of repository in GitHub Enterprise, and then making same former named repo as below steps.
sample
in remoteold-sample
sample
in remoteWeird thing is that I removed local repo but git tries to clone old one even if I try to clone by newly created repo url. The clone url is just automatically redirected to old one even if the new one is existed in remote. I don't know this cause is from server or local git process.
For this reason, the error occurs because the git process fails to compare its local commit history to remote history.
The unrelated histories could tell in above situation.
I ended up to remove renamed old repo in remote and it solved.
git init
+git remote add ...
? What is the remote and what are you trying to do? – max630