$ 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?
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.
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 “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 .
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.
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
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.
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