{"id":2652,"date":"2018-10-10T19:07:53","date_gmt":"2018-10-10T15:07:53","guid":{"rendered":"https:\/\/blog.alwawee.ru\/?p=2652"},"modified":"2018-10-10T19:14:18","modified_gmt":"2018-10-10T15:14:18","slug":"git-merge-three-repos-to-one","status":"publish","type":"post","link":"https:\/\/blog.alwawee.ru\/?p=2652","title":{"rendered":"Merging Three Git Repositories Into One Repository Without Losing File History"},"content":{"rendered":"<p>Let&#8217;s assume that we have three separate git repos named uremont-client, uremont-service, uremont-sdk. We want to create a new repo, named uremont-ios, that contains all those repos in separate folders to have one single repo. <\/p>\n<p>Why do we want to do this? In my case I had two apps and one sdk for them, and it was inconvenient for me to push changes to three separate repos while I was working with these projects and sdk at the same time. <\/p>\n<p>Let&#8217;s start.<\/p>\n<p>Terminal setup to allow git to move all folders except one. We will need this later.<\/p>\n<pre>\r\n$ shopt -s extglob\r\n<\/pre>\n<p>Create a new folder uremont-ios and initialize git repo: <\/p>\n<pre>\r\n$ mkdir uremont-ios \r\n$ cd uremont-ios\r\n$ git init\r\n<\/pre>\n<p>Add remote of first old project uremont-client that we want to merge to the new git repo and fetch it:<\/p>\n<pre>\r\n$ git remote add -f uremont-client git@bitbucket.org:wzbozon\/uremont.git\r\n<\/pre>\n<p>Merge first old project uremont-client to the new repo: <\/p>\n<pre>\r\n$ git merge uremont-client\/master --allow-unrelated-histories\r\n<\/pre>\n<p>Move all folders and files of that old project to the separate folder inside of our new project:<\/p>\n<pre>\r\n$ mkdir uremont-client\r\n$ git mv .\/!(uremont-client) .\/uremont-client\r\n<\/pre>\n<p>Commit changes: <\/p>\n<pre>\r\n$ git commit -m 'Move uremont-client files into subdir'\r\n<\/pre>\n<p>Similarly merge second old project uremont-service to the new repo: <\/p>\n<pre>\r\n$ git remote add -f uremont-service git@bitbucket.org:wzbozon\/uremontservice.git\r\n$ git merge uremont-service\/master --allow-unrelated-histories\r\n$ mkdir uremont-service\r\n$ git mv .\/!(uremont-client|uremont-service) .\/uremont-service\r\n$ git commit -m 'Move uremont-service files into subdir'\r\n<\/pre>\n<p>And third: <\/p>\n<pre>\r\n$ git remote add -f uremont-sdk git@bitbucket.org:wzbozon\/uremont-sdk.git\r\n$ git merge uremont-sdk\/master --allow-unrelated-histories\r\n$ mkdir uremont-sdk\r\n$ git mv .\/!(uremont-client|uremont-service|uremont-sdk) .\/uremont-sdk\r\n$ git commit -m 'Move uremont-sdk files into subdir'\r\n<\/pre>\n<p>Finally, add a new remote to our new repo and push it: <\/p>\n<pre>\r\n$ git remote add origin git@bitbucket.org:wzbozon\/uremont-ios.git\r\n$ git push -u origin master\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Let&#8217;s assume that we have three separate git repos named uremont-client, uremont-service, uremont-sdk. We want to create a new repo, named uremont-ios, that contains all those repos in separate folders to have one single repo. Why do we want to do this? In my case I had two apps and one sdk for them, and [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[170],"tags":[166],"class_list":["post-2652","post","type-post","status-publish","format-standard","hentry","category-other","tag-git"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.6 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Merging Three Git Repositories Into One Repository Without Losing File History - Denis Kutlubaev<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/blog.alwawee.ru\/?p=2652\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Merging Three Git Repositories Into One Repository Without Losing File History - Denis Kutlubaev\" \/>\n<meta property=\"og:description\" content=\"Let&#8217;s assume that we have three separate git repos named uremont-client, uremont-service, uremont-sdk. We want to create a new repo, named uremont-ios, that contains all those repos in separate folders to have one single repo. Why do we want to do this? In my case I had two apps and one sdk for them, and [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/blog.alwawee.ru\/?p=2652\" \/>\n<meta property=\"og:site_name\" content=\"Denis Kutlubaev\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/alwaweemobile\" \/>\n<meta property=\"article:published_time\" content=\"2018-10-10T15:07:53+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2018-10-10T15:14:18+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/blog.alwawee.com\/?attachment_id=1982\" \/>\n<meta name=\"author\" content=\"Denis Kutlubaev\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Denis Kutlubaev\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/?p=2652#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/?p=2652\"},\"author\":{\"name\":\"Denis Kutlubaev\",\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/#\\\/schema\\\/person\\\/58f1f1f57155b48afab83ba53b3e26a7\"},\"headline\":\"Merging Three Git Repositories Into One Repository Without Losing File History\",\"datePublished\":\"2018-10-10T15:07:53+00:00\",\"dateModified\":\"2018-10-10T15:14:18+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/?p=2652\"},\"wordCount\":193,\"commentCount\":0,\"keywords\":[\"Git\"],\"articleSection\":[\"Other\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/blog.alwawee.ru\\\/?p=2652#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/?p=2652\",\"url\":\"https:\\\/\\\/blog.alwawee.ru\\\/?p=2652\",\"name\":\"Merging Three Git Repositories Into One Repository Without Losing File History - Denis Kutlubaev\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/#website\"},\"datePublished\":\"2018-10-10T15:07:53+00:00\",\"dateModified\":\"2018-10-10T15:14:18+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/#\\\/schema\\\/person\\\/58f1f1f57155b48afab83ba53b3e26a7\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/?p=2652#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/blog.alwawee.ru\\\/?p=2652\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/?p=2652#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/blog.alwawee.ru\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Merging Three Git Repositories Into One Repository Without Losing File History\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/#website\",\"url\":\"https:\\\/\\\/blog.alwawee.ru\\\/\",\"name\":\"Denis Kutlubaev\",\"description\":\"iOS Development\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/blog.alwawee.ru\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/#\\\/schema\\\/person\\\/58f1f1f57155b48afab83ba53b3e26a7\",\"name\":\"Denis Kutlubaev\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/346de75d27c818be0aa7fddeada2e50e30cc15b4da6b3b8110c5d766cd2afa34?s=96&d=mm&r=pg\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/346de75d27c818be0aa7fddeada2e50e30cc15b4da6b3b8110c5d766cd2afa34?s=96&d=mm&r=pg\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/346de75d27c818be0aa7fddeada2e50e30cc15b4da6b3b8110c5d766cd2afa34?s=96&d=mm&r=pg\",\"caption\":\"Denis Kutlubaev\"},\"description\":\"iOS Developer, creator of Tornado Browser and many other popular apps\",\"sameAs\":[\"http:\\\/\\\/dennis.alwawee.com\"],\"url\":\"https:\\\/\\\/blog.alwawee.ru\\\/?author=1\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Merging Three Git Repositories Into One Repository Without Losing File History - Denis Kutlubaev","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:\/\/blog.alwawee.ru\/?p=2652","og_locale":"en_US","og_type":"article","og_title":"Merging Three Git Repositories Into One Repository Without Losing File History - Denis Kutlubaev","og_description":"Let&#8217;s assume that we have three separate git repos named uremont-client, uremont-service, uremont-sdk. We want to create a new repo, named uremont-ios, that contains all those repos in separate folders to have one single repo. Why do we want to do this? In my case I had two apps and one sdk for them, and [&hellip;]","og_url":"https:\/\/blog.alwawee.ru\/?p=2652","og_site_name":"Denis Kutlubaev","article_publisher":"https:\/\/www.facebook.com\/alwaweemobile","article_published_time":"2018-10-10T15:07:53+00:00","article_modified_time":"2018-10-10T15:14:18+00:00","og_image":[{"url":"http:\/\/blog.alwawee.com\/?attachment_id=1982","type":"","width":"","height":""}],"author":"Denis Kutlubaev","twitter_misc":{"Written by":"Denis Kutlubaev","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/blog.alwawee.ru\/?p=2652#article","isPartOf":{"@id":"https:\/\/blog.alwawee.ru\/?p=2652"},"author":{"name":"Denis Kutlubaev","@id":"https:\/\/blog.alwawee.ru\/#\/schema\/person\/58f1f1f57155b48afab83ba53b3e26a7"},"headline":"Merging Three Git Repositories Into One Repository Without Losing File History","datePublished":"2018-10-10T15:07:53+00:00","dateModified":"2018-10-10T15:14:18+00:00","mainEntityOfPage":{"@id":"https:\/\/blog.alwawee.ru\/?p=2652"},"wordCount":193,"commentCount":0,"keywords":["Git"],"articleSection":["Other"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/blog.alwawee.ru\/?p=2652#respond"]}]},{"@type":"WebPage","@id":"https:\/\/blog.alwawee.ru\/?p=2652","url":"https:\/\/blog.alwawee.ru\/?p=2652","name":"Merging Three Git Repositories Into One Repository Without Losing File History - Denis Kutlubaev","isPartOf":{"@id":"https:\/\/blog.alwawee.ru\/#website"},"datePublished":"2018-10-10T15:07:53+00:00","dateModified":"2018-10-10T15:14:18+00:00","author":{"@id":"https:\/\/blog.alwawee.ru\/#\/schema\/person\/58f1f1f57155b48afab83ba53b3e26a7"},"breadcrumb":{"@id":"https:\/\/blog.alwawee.ru\/?p=2652#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/blog.alwawee.ru\/?p=2652"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/blog.alwawee.ru\/?p=2652#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/blog.alwawee.ru\/"},{"@type":"ListItem","position":2,"name":"Merging Three Git Repositories Into One Repository Without Losing File History"}]},{"@type":"WebSite","@id":"https:\/\/blog.alwawee.ru\/#website","url":"https:\/\/blog.alwawee.ru\/","name":"Denis Kutlubaev","description":"iOS Development","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/blog.alwawee.ru\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/blog.alwawee.ru\/#\/schema\/person\/58f1f1f57155b48afab83ba53b3e26a7","name":"Denis Kutlubaev","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/346de75d27c818be0aa7fddeada2e50e30cc15b4da6b3b8110c5d766cd2afa34?s=96&d=mm&r=pg","url":"https:\/\/secure.gravatar.com\/avatar\/346de75d27c818be0aa7fddeada2e50e30cc15b4da6b3b8110c5d766cd2afa34?s=96&d=mm&r=pg","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/346de75d27c818be0aa7fddeada2e50e30cc15b4da6b3b8110c5d766cd2afa34?s=96&d=mm&r=pg","caption":"Denis Kutlubaev"},"description":"iOS Developer, creator of Tornado Browser and many other popular apps","sameAs":["http:\/\/dennis.alwawee.com"],"url":"https:\/\/blog.alwawee.ru\/?author=1"}]}},"_links":{"self":[{"href":"https:\/\/blog.alwawee.ru\/index.php?rest_route=\/wp\/v2\/posts\/2652","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.alwawee.ru\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.alwawee.ru\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.alwawee.ru\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.alwawee.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2652"}],"version-history":[{"count":5,"href":"https:\/\/blog.alwawee.ru\/index.php?rest_route=\/wp\/v2\/posts\/2652\/revisions"}],"predecessor-version":[{"id":2657,"href":"https:\/\/blog.alwawee.ru\/index.php?rest_route=\/wp\/v2\/posts\/2652\/revisions\/2657"}],"wp:attachment":[{"href":"https:\/\/blog.alwawee.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2652"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.alwawee.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2652"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.alwawee.ru\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2652"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}