{"id":32320,"date":"2022-12-20T18:58:34","date_gmt":"2022-12-20T18:58:34","guid":{"rendered":"https:\/\/www.devopsschool.com\/blog\/?p=32320"},"modified":"2022-12-23T05:44:30","modified_gmt":"2022-12-23T05:44:30","slug":"git-tutorials-merge-code-between-multiple-repos","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/git-tutorials-merge-code-between-multiple-repos\/","title":{"rendered":"Git Tutorials: Merge code between multiple repos"},"content":{"rendered":"\n<p>It is something you can do locally though, from your machine, the following way:<\/p>\n\n\n\n<p><strong>1.<\/strong>&nbsp;Assume you have repos&nbsp;<a href=\"https:\/\/bitbucket.org\/my-workspace\/repo-1\/\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/bitbucket.org\/my-workspace\/repo-1\/<\/a>&nbsp;and&nbsp;<a href=\"https:\/\/bitbucket.org\/my-workspace\/repo-2\/\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/bitbucket.org\/my-workspace\/repo-2\/<\/a>, and you want to merge code from repo-2 to repo-1<\/p>\n\n\n\n<p>Navigate to your local clone of repo-1<\/p>\n\n\n\n<p><strong>2.<\/strong>&nbsp;Add the second repo as a remote with a command like the following (I&#8217;m adding the SSHL URL; if you don&#8217;t use SSH, you can replace with the HTTPS URL:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">git remote add second_remote git@bitbucket.org:my-workspace\/repo-2.git<\/pre>\n\n\n\n<p>then<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">git fetch --all<\/pre>\n\n\n\n<p><strong>3.<\/strong>&nbsp;Then create (in repo-1) a branch that tracks the remote branch from repo-2 you want to merge, named e.g. feature2-branch<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">git checkout -b feature2-branch --track second_remote\/feature2-branch<\/pre>\n\n\n\n<p><strong>4.<\/strong>&nbsp;If you wang to merge that to master branch of repo-1, then you can do<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">git merge master --allow-unrelated-histories<\/pre>\n\n\n\n<p>The &#8211;allow-unrelated-histories will be necessary if the repos have no common history, otherwise Git will refuse to make the merge.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>It is something you can do locally though, from your machine, the following way: 1.&nbsp;Assume you have repos&nbsp;https:\/\/bitbucket.org\/my-workspace\/repo-1\/&nbsp;and&nbsp;https:\/\/bitbucket.org\/my-workspace\/repo-2\/, and you want to merge code from repo-2 to repo-1 Navigate to your local clone of repo-1 2.&nbsp;Add the second repo as a remote with a command like the following (I&#8217;m adding the SSHL URL; if you&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"_kad_post_classname":"","_joinchat":[],"footnotes":""},"categories":[2],"tags":[],"class_list":["post-32320","post","type-post","status-publish","format-standard","hentry","category-uncategorised"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/32320","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=32320"}],"version-history":[{"count":1,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/32320\/revisions"}],"predecessor-version":[{"id":32321,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/32320\/revisions\/32321"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=32320"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=32320"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=32320"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}