{"id":19619,"date":"2020-07-17T01:35:04","date_gmt":"2020-07-17T08:35:04","guid":{"rendered":"https:\/\/careerkarma.com\/blog\/?p=19619"},"modified":"2023-12-01T03:55:28","modified_gmt":"2023-12-01T11:55:28","slug":"git-fatal-refusing-to-merge-unrelated-histories","status":"publish","type":"post","link":"https:\/\/careerkarma.com\/blog\/git-fatal-refusing-to-merge-unrelated-histories\/","title":{"rendered":"How to Solve fatal: refusing to merge unrelated histories"},"content":{"rendered":"\n<p>After using Git for a while, you\u2019ll notice that there\u2019s a lot of mistakes that can be difficult to fix. This isn\u2019t the case with the fatal: refusing to merge unrelated histories error. Unlike a number of other errors, this issue has one solution that you can reuse whenever you encounter it.<br><\/p>\n\n\n\n<p>In this guide, we\u2019re going to talk about how to solve the fatal: refusing to merge unrelated histories errors in Git. Let\u2019s get started!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Why Does the Error Occur?<\/h2>\n\n\n\n<p>The error <code>fatal: refusing to merge unrelated histories<\/code> occurs when two unrelated projects are merged into a single branch. This error arises because each project has its own history of commits and tags. These two histories will be incompatible with each other.<br><\/p>\n\n\n\n<p>There are two main scenarios when this error may arise.<br><\/p>\n\n\n\n<p>When you create a new repository, make a few commits, and try to pull from another remote repository, this error can occur. This error will be displayed because the local repository with which you are working will have a different history to the project which you are trying to retrieve.<br><\/p>\n\n\n\n<p>You may encounter this error if the .git directory inside a project that has been deleted or corrupted. In this case, the Git command line may not be able to read your local project\u2019s history.<br><\/p>\n\n\n\n<p>When you try to push data to or pull data from a remote repository, this error will occur. This is because Git doesn\u2019t know if the remote repository is compatible with your current repository.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How to Solve \u2018fatal: refusing to merge unrelated histories\u2019<\/h2>\n\n\n\n<p>We\u2019ve done enough talking. To solve this issue, you can use the <code>--allow-unrelated-histories<\/code> flag when pulling data from a repository:<br><\/p>\n\n\n\n<p>Git pull origin master &#8211;allow-unrelated-histories<br><\/p>\n\n\n\n<p>You\u2019ll want to substitute <code>origin<\/code> with the remote repository from which you are pulling resources. You should replace <code>master<\/code> with the branch that you want to retrieve.<br><\/p>\n\n\n\n<p>This command was added to handle the rare event that you are working with two projects that have their own branches.&nbsp;<br><\/p>\n\n\n\n<p>Alternatively, you could clone a new version of the remote repository using <a href=\"https:\/\/careerkarma.com\/blog\/git-clone\">git clone<\/a> and start over. However, this is not usually necessary.<br><\/p>\n\n\n\n<p>You can read more about the &#8211;allow-unrelated-histories flag on the official <a href=\"https:\/\/github.com\/git\/git\/blob\/master\/Documentation\/RelNotes\/2.9.0.txt#L58-L68\" target=\"_blank\" rel=\"noopener\" rel=\"nofollow\">Git documentation<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>The fatal: refusing to merge unrelated histories error occurs when either a .git directory is unreadable or when you are trying to pull data from a repository with its own commit history. This error tells you that you are trying to Git merge two unrelated projects to the same work tree.<br><\/p>\n\n\n\n<p>Now you\u2019re ready to solve this error using the &#8211;allow-unrelated-histories flag like an expert!<br><\/p>\n","protected":false},"excerpt":{"rendered":"After using Git for a while, you\u2019ll notice that there\u2019s a lot of mistakes that can be difficult to fix. This isn\u2019t the case with the fatal: refusing to merge unrelated histories error. Unlike a number of other errors, this issue has one solution that you can reuse whenever you encounter it. In this guide,&hellip;","protected":false},"author":240,"featured_media":19673,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[17286],"tags":[],"class_list":{"0":"post-19619","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-git"},"acf":{"post_sub_title":"","sprint_id":"","query_class":"Git","school_sft":"","parent_sft":"","school_privacy_policy":"","has_review":null,"is_sponser_post":"","is_guest_post":""},"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.0 (Yoast SEO v27.0) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>How to Solve fatal: refusing to merge unrelated histories | Career Karma<\/title>\n<meta name=\"description\" content=\"The fatal: refusing to merge unrelated histories git error can be resolved using the --allow-unrelated-histories flag. On Career Karma, learn how to resolve this common error.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/careerkarma.com\/blog\/git-fatal-refusing-to-merge-unrelated-histories\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Solve fatal: refusing to merge unrelated histories\" \/>\n<meta property=\"og:description\" content=\"The fatal: refusing to merge unrelated histories git error can be resolved using the --allow-unrelated-histories flag. On Career Karma, learn how to resolve this common error.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/careerkarma.com\/blog\/git-fatal-refusing-to-merge-unrelated-histories\/\" \/>\n<meta property=\"og:site_name\" content=\"Career Karma\" \/>\n<meta property=\"article:publisher\" content=\"http:\/\/facebook.com\/careerkarmaapp\" \/>\n<meta property=\"article:published_time\" content=\"2020-07-17T08:35:04+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-12-01T11:55:28+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/07\/brina-blum-Bb_X4JgSqIM-unsplash.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1000\" \/>\n\t<meta property=\"og:image:height\" content=\"667\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"James Gallagher\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@career_karma\" \/>\n<meta name=\"twitter:site\" content=\"@career_karma\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"James Gallagher\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/careerkarma.com\/blog\/git-fatal-refusing-to-merge-unrelated-histories\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/git-fatal-refusing-to-merge-unrelated-histories\/\"},\"author\":{\"name\":\"James Gallagher\",\"@id\":\"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94\"},\"headline\":\"How to Solve fatal: refusing to merge unrelated histories\",\"datePublished\":\"2020-07-17T08:35:04+00:00\",\"dateModified\":\"2023-12-01T11:55:28+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/git-fatal-refusing-to-merge-unrelated-histories\/\"},\"wordCount\":447,\"commentCount\":0,\"image\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/git-fatal-refusing-to-merge-unrelated-histories\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/07\/brina-blum-Bb_X4JgSqIM-unsplash.jpg\",\"articleSection\":[\"Git\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/careerkarma.com\/blog\/git-fatal-refusing-to-merge-unrelated-histories\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/careerkarma.com\/blog\/git-fatal-refusing-to-merge-unrelated-histories\/\",\"url\":\"https:\/\/careerkarma.com\/blog\/git-fatal-refusing-to-merge-unrelated-histories\/\",\"name\":\"How to Solve fatal: refusing to merge unrelated histories | Career Karma\",\"isPartOf\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/git-fatal-refusing-to-merge-unrelated-histories\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/git-fatal-refusing-to-merge-unrelated-histories\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/07\/brina-blum-Bb_X4JgSqIM-unsplash.jpg\",\"datePublished\":\"2020-07-17T08:35:04+00:00\",\"dateModified\":\"2023-12-01T11:55:28+00:00\",\"author\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94\"},\"description\":\"The fatal: refusing to merge unrelated histories git error can be resolved using the --allow-unrelated-histories flag. On Career Karma, learn how to resolve this common error.\",\"breadcrumb\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/git-fatal-refusing-to-merge-unrelated-histories\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/careerkarma.com\/blog\/git-fatal-refusing-to-merge-unrelated-histories\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/careerkarma.com\/blog\/git-fatal-refusing-to-merge-unrelated-histories\/#primaryimage\",\"url\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/07\/brina-blum-Bb_X4JgSqIM-unsplash.jpg\",\"contentUrl\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/07\/brina-blum-Bb_X4JgSqIM-unsplash.jpg\",\"width\":1000,\"height\":667},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/careerkarma.com\/blog\/git-fatal-refusing-to-merge-unrelated-histories\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Blog\",\"item\":\"https:\/\/careerkarma.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Git\",\"item\":\"https:\/\/careerkarma.com\/blog\/git\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"How to Solve fatal: refusing to merge unrelated histories\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/careerkarma.com\/blog\/#website\",\"url\":\"https:\/\/careerkarma.com\/blog\/\",\"name\":\"Career Karma\",\"description\":\"Latest Coding Bootcamp News &amp; Career Hacks from Industry Insiders\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/careerkarma.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94\",\"name\":\"James Gallagher\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg\",\"contentUrl\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg\",\"caption\":\"James Gallagher\"},\"description\":\"James Gallagher is a self-taught programmer and the technical content manager at Career Karma. He has experience in range of programming languages and extensive expertise in Python, HTML, CSS, and JavaScript. James has written hundreds of programming tutorials, and he frequently contributes to publications like Codecademy, Treehouse, Repl.it, Afrotech, and others.\",\"url\":\"https:\/\/careerkarma.com\/blog\/author\/jamesgallagher\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"How to Solve fatal: refusing to merge unrelated histories | Career Karma","description":"The fatal: refusing to merge unrelated histories git error can be resolved using the --allow-unrelated-histories flag. On Career Karma, learn how to resolve this common error.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/careerkarma.com\/blog\/git-fatal-refusing-to-merge-unrelated-histories\/","og_locale":"en_US","og_type":"article","og_title":"How to Solve fatal: refusing to merge unrelated histories","og_description":"The fatal: refusing to merge unrelated histories git error can be resolved using the --allow-unrelated-histories flag. On Career Karma, learn how to resolve this common error.","og_url":"https:\/\/careerkarma.com\/blog\/git-fatal-refusing-to-merge-unrelated-histories\/","og_site_name":"Career Karma","article_publisher":"http:\/\/facebook.com\/careerkarmaapp","article_published_time":"2020-07-17T08:35:04+00:00","article_modified_time":"2023-12-01T11:55:28+00:00","og_image":[{"width":1000,"height":667,"url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/07\/brina-blum-Bb_X4JgSqIM-unsplash.jpg","type":"image\/jpeg"}],"author":"James Gallagher","twitter_card":"summary_large_image","twitter_creator":"@career_karma","twitter_site":"@career_karma","twitter_misc":{"Written by":"James Gallagher","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/careerkarma.com\/blog\/git-fatal-refusing-to-merge-unrelated-histories\/#article","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/git-fatal-refusing-to-merge-unrelated-histories\/"},"author":{"name":"James Gallagher","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94"},"headline":"How to Solve fatal: refusing to merge unrelated histories","datePublished":"2020-07-17T08:35:04+00:00","dateModified":"2023-12-01T11:55:28+00:00","mainEntityOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/git-fatal-refusing-to-merge-unrelated-histories\/"},"wordCount":447,"commentCount":0,"image":{"@id":"https:\/\/careerkarma.com\/blog\/git-fatal-refusing-to-merge-unrelated-histories\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/07\/brina-blum-Bb_X4JgSqIM-unsplash.jpg","articleSection":["Git"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/careerkarma.com\/blog\/git-fatal-refusing-to-merge-unrelated-histories\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/careerkarma.com\/blog\/git-fatal-refusing-to-merge-unrelated-histories\/","url":"https:\/\/careerkarma.com\/blog\/git-fatal-refusing-to-merge-unrelated-histories\/","name":"How to Solve fatal: refusing to merge unrelated histories | Career Karma","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/git-fatal-refusing-to-merge-unrelated-histories\/#primaryimage"},"image":{"@id":"https:\/\/careerkarma.com\/blog\/git-fatal-refusing-to-merge-unrelated-histories\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/07\/brina-blum-Bb_X4JgSqIM-unsplash.jpg","datePublished":"2020-07-17T08:35:04+00:00","dateModified":"2023-12-01T11:55:28+00:00","author":{"@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94"},"description":"The fatal: refusing to merge unrelated histories git error can be resolved using the --allow-unrelated-histories flag. On Career Karma, learn how to resolve this common error.","breadcrumb":{"@id":"https:\/\/careerkarma.com\/blog\/git-fatal-refusing-to-merge-unrelated-histories\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/careerkarma.com\/blog\/git-fatal-refusing-to-merge-unrelated-histories\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/careerkarma.com\/blog\/git-fatal-refusing-to-merge-unrelated-histories\/#primaryimage","url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/07\/brina-blum-Bb_X4JgSqIM-unsplash.jpg","contentUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/07\/brina-blum-Bb_X4JgSqIM-unsplash.jpg","width":1000,"height":667},{"@type":"BreadcrumbList","@id":"https:\/\/careerkarma.com\/blog\/git-fatal-refusing-to-merge-unrelated-histories\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog","item":"https:\/\/careerkarma.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Git","item":"https:\/\/careerkarma.com\/blog\/git\/"},{"@type":"ListItem","position":3,"name":"How to Solve fatal: refusing to merge unrelated histories"}]},{"@type":"WebSite","@id":"https:\/\/careerkarma.com\/blog\/#website","url":"https:\/\/careerkarma.com\/blog\/","name":"Career Karma","description":"Latest Coding Bootcamp News &amp; Career Hacks from Industry Insiders","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/careerkarma.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94","name":"James Gallagher","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg","contentUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg","caption":"James Gallagher"},"description":"James Gallagher is a self-taught programmer and the technical content manager at Career Karma. He has experience in range of programming languages and extensive expertise in Python, HTML, CSS, and JavaScript. James has written hundreds of programming tutorials, and he frequently contributes to publications like Codecademy, Treehouse, Repl.it, Afrotech, and others.","url":"https:\/\/careerkarma.com\/blog\/author\/jamesgallagher\/"}]}},"_links":{"self":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts\/19619","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/users\/240"}],"replies":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/comments?post=19619"}],"version-history":[{"count":0,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts\/19619\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media\/19673"}],"wp:attachment":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media?parent=19619"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/categories?post=19619"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/tags?post=19619"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}