Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GIT Fatal : refusing to merge unrelated histories

Tags:

$ git pull origin master From https://bitbucket.org/tecgenome/chl-v2.0-html  * branch            master     -> FETCH_HEAD fatal: refusing to merge unrelated histories 

How can I avoid or get past that error message?

like image 947
Mukesh Rawat Avatar asked Oct 14 '16 06:10

Mukesh Rawat


People also ask

How do I fix fatal refusing to merge unrelated histories?

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.

How do I merge a branch with unrelated histories?

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.

What is unrelated histories in git?

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 .

How do I accept all incoming changes in git?

Git : accept all incoming changes Similar to how we used --ours to ignore incoming changes, you can use --theirs to ignore all changes made by yourself and merge other commits. In the case that you wish accept all incoming changes in the branch, you can cd to the repository and run git against the current directory.


2 Answers

Since Git 2.9 (April 2016), you can try:

git pull --allow-unrelated-histories origin master 

But check why those branches are no longer common though.
May be there was a force push rewritting all the history of origin/master.

In which case, if you don't have local commits of your own, it is best to reset your branch to the new one:

Warning: this will delete any untracked file, and reset your repository to origin/master
(You can try it in a copy of your current local clone)

git fetch  # Warning: RESET AHEAD git reset --hard origin/master 
like image 190
VonC Avatar answered Oct 03 '22 14:10

VonC


I did meet the same issue, and try the command it gets work.

git merge abbranch --allow-unrelated-histories

here we assume that abbranch is unrelated to current branch. Above command merge abbranch to current branch.

like image 40
knight2016 Avatar answered Oct 03 '22 14:10

knight2016