{"id":1274,"date":"2021-09-08T15:36:56","date_gmt":"2021-09-08T13:36:56","guid":{"rendered":"https:\/\/nguenkam.com\/blog\/?p=1274"},"modified":"2023-08-03T09:54:54","modified_gmt":"2023-08-03T07:54:54","slug":"the-fatal-refusing-to-merge-unrelated-histories-git-error","status":"publish","type":"post","link":"https:\/\/nguenkam.com\/blog\/index.php\/2021\/09\/08\/the-fatal-refusing-to-merge-unrelated-histories-git-error\/","title":{"rendered":"The \u201cfatal: refusing to merge unrelated histories\u201d Git error"},"content":{"rendered":"\n<p>The&nbsp;<strong>\u201cfatal: refusing to merge unrelated histories\u201d<\/strong>&nbsp;Git error occurs when two&nbsp;<em>unrelated<\/em>&nbsp;projects are merged (i.e., projects that are not aware of each other\u2019s existence and have mismatching commit histories).<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>Consider the following two cases that throw this error:<\/p>\n\n\n\n<ul><li>You have cloned a project and, somehow, the&nbsp;<code><strong>.git<\/strong><\/code>&nbsp;directory got deleted or corrupted. This leads Git to be unaware of your local history and will, therefore, cause it to throw this error when you try to push<em>  to<\/em>&nbsp;or&nbsp;<em>pull from<\/em>&nbsp;the remote repository.<\/li><li>You have created a new repository, added a few&nbsp;<em>commits<\/em>&nbsp;to it, and now you are trying to&nbsp;<em>pull<\/em>&nbsp;from a remote repository that already has some commits of its own. Git will also throw the error in this case, since it has no idea how the two projects are related.<\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" src=\"https:\/\/nguenkam.com\/blog\/wp-content\/uploads\/2021\/09\/image.png\" alt=\"\" class=\"wp-image-1277\" width=\"342\" height=\"319\" srcset=\"https:\/\/nguenkam.com\/blog\/wp-content\/uploads\/2021\/09\/image.png 535w, https:\/\/nguenkam.com\/blog\/wp-content\/uploads\/2021\/09\/image-300x280.png 300w\" sizes=\"(max-width: 342px) 100vw, 342px\" \/><\/figure>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3><span class=\"has-inline-color has-light-green-cyan-color\"><strong>Solution<\/strong><\/span><\/h3>\n\n\n\n<p>The error is resolved by toggling the&nbsp;<em>allow-unrelated-histories<\/em>&nbsp;switch. After a&nbsp;<code>git pull<\/code>&nbsp;or&nbsp;<code>git merge<\/code>&nbsp;command, add the following tag:<\/p>\n\n\n\n<p>*Checkout your local projet. <em><strong>The one you want to push in the remote branch<\/strong>. <\/em><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>git checkout &lt;local-branche&gt;<\/code><\/pre>\n\n\n\n<p> Then pull or merge it , into the remote branche.  ( <em><strong>Where you want to push the new project )<\/strong><\/em>. <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>git pull origin master --allow-unrelated-histories<\/code><\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The&nbsp;\u201cfatal: refusing to merge unrelated histories\u201d&nbsp;Git error occurs when two&nbsp;unrelated&nbsp;projects are merged (i.e., projects that are not aware of each other\u2019s existence and have mismatching commit histories). Consider the following two cases that throw this error: You have cloned a project and, somehow, the&nbsp;.git&nbsp;directory got deleted or corrupted. This leads Git to be unaware of [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":807,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[60,33],"tags":[257,351,61,353,352],"_links":{"self":[{"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/1274"}],"collection":[{"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=1274"}],"version-history":[{"count":3,"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/1274\/revisions"}],"predecessor-version":[{"id":2803,"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/1274\/revisions\/2803"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/media\/807"}],"wp:attachment":[{"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=1274"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=1274"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=1274"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}