{"id":50,"date":"2012-07-24T19:03:23","date_gmt":"2012-07-24T19:03:23","guid":{"rendered":"https:\/\/www.peopleperhour.com\/engineering\/?p=50"},"modified":"2012-07-24T19:03:23","modified_gmt":"2012-07-24T19:03:23","slug":"moving-a-git-directory-on-a-separate-repo-with-the-history","status":"publish","type":"post","link":"https:\/\/www.peopleperhour.com\/engineering\/2012\/07\/24\/moving-a-git-directory-on-a-separate-repo-with-the-history\/","title":{"rendered":"Moving a Git directory on a separate repo with the history"},"content":{"rendered":"<p>During your life as a busy developer, you might reach a point were your Git repo is huge and part of it would make sense to move it into a separate repository. It happened to us today in PPH, when we decided to move all our puppet modules\u00a0out of our old configuration repository.<\/p>\n<p>To start with, I cloned the existing repository into a separate folder so that I could mess with it as I liked (line 1) then I removed the origin to avoid accidental commit\/push (line 3) and stripped out everything except the content of the directory I wanted to move in the separate repository using <a title=\"git-filter-branch\" href=\"http:\/\/www.kernel.org\/pub\/software\/scm\/git\/docs\/git-filter-branch.html\" target=\"_blank\">git-filter-branch<\/a> (line 4)<\/p>\n<pre class=\"lang:sh decode:true\" title=\"cleanup the repo\">git clone repoONE\r\ncd repoONE\r\ngit remote rm origin\r\ngit filter-branch --subdirectory-filter exampleDir -- --all<\/pre>\n<p>At that point, the root folder of repoONE contained only the files of the exampleDir folder while the rest was wiped away. The next step was to create a new repository, add the repoONE as remote (line 4) and pull from it (line 5) then remove the remote repoONE (line 6).<strong><\/strong><\/p>\n<pre class=\"lang:sh decode:true\" title=\"move it\">mkdir repoTWO\r\ncd repoTWO\r\ngit init\r\ngit remote add repoONE repoONEdirecotry\r\ngit pull repoONE master\r\ngit remote rm repoONE<\/pre>\n<p>RepoTWO, at that point, contained all the files I wanted along with the history.<\/p>\n<p><strong>Job Done!<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>During your life as a busy developer, you might reach a point were your Git repo is huge and part of it would make sense to move it into a separate repository. It happened to us today in PPH, when we decided to move all&#8230;<\/p>\n","protected":false},"author":35,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[11],"tags":[14,12,13],"class_list":["post-50","post","type-post","status-publish","format-standard","hentry","category-git","tag-devops","tag-git-2","tag-shell"],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p2CA4w-O","jetpack_likes_enabled":true,"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.peopleperhour.com\/engineering\/wp-json\/wp\/v2\/posts\/50","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.peopleperhour.com\/engineering\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.peopleperhour.com\/engineering\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.peopleperhour.com\/engineering\/wp-json\/wp\/v2\/users\/35"}],"replies":[{"embeddable":true,"href":"https:\/\/www.peopleperhour.com\/engineering\/wp-json\/wp\/v2\/comments?post=50"}],"version-history":[{"count":6,"href":"https:\/\/www.peopleperhour.com\/engineering\/wp-json\/wp\/v2\/posts\/50\/revisions"}],"predecessor-version":[{"id":56,"href":"https:\/\/www.peopleperhour.com\/engineering\/wp-json\/wp\/v2\/posts\/50\/revisions\/56"}],"wp:attachment":[{"href":"https:\/\/www.peopleperhour.com\/engineering\/wp-json\/wp\/v2\/media?parent=50"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.peopleperhour.com\/engineering\/wp-json\/wp\/v2\/categories?post=50"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.peopleperhour.com\/engineering\/wp-json\/wp\/v2\/tags?post=50"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}