{"id":56840,"date":"2023-03-12T13:57:43","date_gmt":"2023-03-12T08:27:43","guid":{"rendered":"https:\/\/www.tothenew.com\/blog\/?p=56840"},"modified":"2023-03-14T14:14:27","modified_gmt":"2023-03-14T08:44:27","slug":"git-add-multiple-repositoriesbitbucket-github-to-the-same-project","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/git-add-multiple-repositoriesbitbucket-github-to-the-same-project\/","title":{"rendered":"Git: Add multiple repositories(Bitbucket, Github) to the same project."},"content":{"rendered":"<p>In this blog, we are going to learn about an important feature (migration across repositories providers) of one of the most common technologies we came across in our day-to-day development, GIT.<\/p>\n<p>I mainly used to do R&amp;D work on my private repositories, on bitbucket, as it supports unlimited private repositories space. But after some time, when I started contributing to open source, I realized that GitHub is better at it and I want to use some of my already done work. Therefore, I need to migrate some of my repositories to bitbucket.<\/p>\n<p>Prerequisites: a Bitbucket repository (where original code is present) and a GitHub repository(target repository where the code is to be moved).<\/p>\n<p>Let&#8217;s see how I achieve it:<\/p>\n<p>Step 1:\u00a0 Clone the code from bitbucket to your local system using the git clone command.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\" wp-image-56832 aligncenter\" src=\"\/blog\/wp-ttn-blog\/uploads\/2023\/03\/Screenshot-3-1024x576.png\" alt=\"\" width=\"526\" height=\"296\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2023\/03\/Screenshot-3-1024x576.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2023\/03\/Screenshot-3-300x169.png 300w, \/blog\/wp-ttn-blog\/uploads\/2023\/03\/Screenshot-3-768x432.png 768w, \/blog\/wp-ttn-blog\/uploads\/2023\/03\/Screenshot-3-1536x864.png 1536w, \/blog\/wp-ttn-blog\/uploads\/2023\/03\/Screenshot-3-624x351.png 624w, \/blog\/wp-ttn-blog\/uploads\/2023\/03\/Screenshot-3.png 1920w\" sizes=\"(max-width: 526px) 100vw, 526px\" \/><\/p>\n<blockquote>\n<pre>git clone https:\/\/dheerajgupta217@bitbucket.org\/dheerajgupta217\/bitbucketrepo.<\/pre>\n<p><span style=\"text-decoration: underline;\">Output<\/span>:<\/p>\n<p>git<br \/>\nCloning into &#8216;bitbucketrepo&#8217;&#8230;<br \/>\nremote: Enumerating objects: 13, done.<br \/>\nremote: Counting objects: 100% (13\/13), done.<br \/>\nremote: Compressing objects: 100% (12\/12), done.<br \/>\nremote: Total 13 (delta 2), reused 0 (delta 0), pack-reused 0<br \/>\nUnpacking objects: 100% (13\/13), 1.96 KiB | 49.00 KiB\/s, done.<\/p><\/blockquote>\n<p>Step 2:\u00a0 Move to the location where the project is cloned<\/p>\n<blockquote>\n<pre> cd bitbucketrepo\/<\/pre>\n<\/blockquote>\n<p>Step 3:\u00a0 Add the secondary repository origin with a different name (I used <strong>github<\/strong> for simplicity reasons)<\/p>\n<blockquote>\n<pre>git remote add <strong>github<\/strong> https:\/\/github.com\/dheerajgupta217\/secondary_repository.<\/pre>\n<\/blockquote>\n<p>Step 4:\u00a0 Move your master to the new repository<\/p>\n<blockquote>\n<pre> git push github master<\/pre>\n<p><span style=\"text-decoration: underline;\">Output:<\/span><\/p>\n<p>Enumerating objects: 13, done.<br \/>\nCounting objects: 100% (13\/13), done.<br \/>\nDelta compression using up to 8 threads<br \/>\nCompressing objects: 100% (12\/12), done.<br \/>\nWriting objects: 100% (13\/13), 1.98 KiB | 1015.00 KiB\/s, done.<br \/>\nTotal 13 (delta 2), reused 0 (delta 0), pack-reused 0<br \/>\nremote: Resolving deltas: 100% (2\/2), done.<br \/>\nTo https:\/\/github.com\/dheerajgupta217\/secondary_repository.git<br \/>\n* [new branch] master -&gt; master<\/p><\/blockquote>\n<p>Step 5:\u00a0 Set the URL of the new repository to the origin added.<\/p>\n<blockquote>\n<pre> git remote set-url github https:\/\/github.com\/dheerajgupta217\/secondary_repository<\/pre>\n<\/blockquote>\n<p>Step 6:\u00a0 Check if both repositories are working.<\/p>\n<blockquote>\n<pre>git branch -a<\/pre>\n<p><span style=\"text-decoration: underline;\">Output<\/span>:<\/p>\n<pre>* master\r\nremotes\/github\/master\r\nremotes\/origin\/HEAD -&gt; origin\/master\r\nremotes\/origin\/master<\/pre>\n<\/blockquote>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"wp-image-56838 aligncenter\" src=\"\/blog\/wp-ttn-blog\/uploads\/2023\/03\/Screenshot-9-1024x576.png\" alt=\"Github repo\" width=\"520\" height=\"293\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2023\/03\/Screenshot-9-1024x576.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2023\/03\/Screenshot-9-300x169.png 300w, \/blog\/wp-ttn-blog\/uploads\/2023\/03\/Screenshot-9-768x432.png 768w, \/blog\/wp-ttn-blog\/uploads\/2023\/03\/Screenshot-9-1536x864.png 1536w, \/blog\/wp-ttn-blog\/uploads\/2023\/03\/Screenshot-9-624x351.png 624w, \/blog\/wp-ttn-blog\/uploads\/2023\/03\/Screenshot-9.png 1920w\" sizes=\"(max-width: 520px) 100vw, 520px\" \/><\/p>\n<p>Voila, the git migration is done<\/p>\n<p>Testing the migration activity:<\/p>\n<p>Step 1: Add a new branch to the bitbucket and push it.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"wp-image-56834 aligncenter\" src=\"\/blog\/wp-ttn-blog\/uploads\/2023\/03\/Screenshot-5-1024x576.png\" alt=\"\" width=\"433\" height=\"244\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2023\/03\/Screenshot-5-1024x576.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2023\/03\/Screenshot-5-300x169.png 300w, \/blog\/wp-ttn-blog\/uploads\/2023\/03\/Screenshot-5-768x432.png 768w, \/blog\/wp-ttn-blog\/uploads\/2023\/03\/Screenshot-5-1536x864.png 1536w, \/blog\/wp-ttn-blog\/uploads\/2023\/03\/Screenshot-5-624x351.png 624w, \/blog\/wp-ttn-blog\/uploads\/2023\/03\/Screenshot-5.png 1920w\" sizes=\"(max-width: 433px) 100vw, 433px\" \/><\/p>\n<blockquote>\n<pre>git checkout -b test_branch\r\ngit push origin test_branch<\/pre>\n<\/blockquote>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"wp-image-56835 aligncenter\" src=\"\/blog\/wp-ttn-blog\/uploads\/2023\/03\/Screenshot-6-1024x576.png\" alt=\"\" width=\"382\" height=\"215\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2023\/03\/Screenshot-6-1024x576.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2023\/03\/Screenshot-6-300x169.png 300w, \/blog\/wp-ttn-blog\/uploads\/2023\/03\/Screenshot-6-768x432.png 768w, \/blog\/wp-ttn-blog\/uploads\/2023\/03\/Screenshot-6-1536x864.png 1536w, \/blog\/wp-ttn-blog\/uploads\/2023\/03\/Screenshot-6-624x351.png 624w, \/blog\/wp-ttn-blog\/uploads\/2023\/03\/Screenshot-6.png 1920w\" sizes=\"(max-width: 382px) 100vw, 382px\" \/><\/p>\n<p>Step 2: Push the same branch to GitHub now.<\/p>\n<blockquote>\n<pre>git push github test_branch<\/pre>\n<\/blockquote>\n<p><span style=\"text-decoration: underline;\">Output<\/span>:<\/p>\n<blockquote>\n<pre>Total 0 (delta 0), reused 0 (delta 0), pack-reused 0\r\nremote:\r\nremote: Create a pull request for 'test_branch' on GitHub by visiting:\r\nremote: https:\/\/github.com\/dheerajgupta217\/secondary_repository\/pull\/new\/test_branch\r\nremote:\r\nTo https:\/\/github.com\/dheerajgupta217\/secondary_repository\r\n* [new branch] test_branch -&gt; test_branch<\/pre>\n<\/blockquote>\n<p><img decoding=\"async\" loading=\"lazy\" class=\" wp-image-56837 aligncenter\" src=\"\/blog\/wp-ttn-blog\/uploads\/2023\/03\/Screenshot-8-1024x576.png\" alt=\"\" width=\"502\" height=\"282\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2023\/03\/Screenshot-8-1024x576.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2023\/03\/Screenshot-8-300x169.png 300w, \/blog\/wp-ttn-blog\/uploads\/2023\/03\/Screenshot-8-768x432.png 768w, \/blog\/wp-ttn-blog\/uploads\/2023\/03\/Screenshot-8-1536x864.png 1536w, \/blog\/wp-ttn-blog\/uploads\/2023\/03\/Screenshot-8-624x351.png 624w, \/blog\/wp-ttn-blog\/uploads\/2023\/03\/Screenshot-8.png 1920w\" sizes=\"(max-width: 502px) 100vw, 502px\" \/><\/p>\n<p>The branch and the code must be created in GitHub.<\/p>\n<p><span style=\"text-decoration: underline;\"><strong>Use Case:<\/strong><\/span><\/p>\n<p>Recently for one of our clients, this use case is being used where the code is needed to be moved to code-commit form bitbucket and the client requires his old code as well intact. Migration for it was achieved using the below-mentioned steps.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-56861\" src=\"\/blog\/wp-ttn-blog\/uploads\/2023\/03\/Screenshot-2023-03-14-135556.png\" alt=\"\" width=\"928\" height=\"553\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2023\/03\/Screenshot-2023-03-14-135556.png 928w, \/blog\/wp-ttn-blog\/uploads\/2023\/03\/Screenshot-2023-03-14-135556-300x179.png 300w, \/blog\/wp-ttn-blog\/uploads\/2023\/03\/Screenshot-2023-03-14-135556-768x458.png 768w, \/blog\/wp-ttn-blog\/uploads\/2023\/03\/Screenshot-2023-03-14-135556-624x372.png 624w\" sizes=\"(max-width: 928px) 100vw, 928px\" \/><\/p>\n<div class=\"ap-custom-wrapper\"><\/div><!--ap-custom-wrapper-->","protected":false},"excerpt":{"rendered":"<p>In this blog, we are going to learn about an important feature (migration across repositories providers) of one of the most common technologies we came across in our day-to-day development, GIT. I mainly used to do R&amp;D work on my private repositories, on bitbucket, as it supports unlimited private repositories space. But after some time, [&hellip;]<\/p>\n","protected":false},"author":1352,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":111},"categories":[2348,1],"tags":[4279,375,503,5130],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/56840"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/1352"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=56840"}],"version-history":[{"count":6,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/56840\/revisions"}],"predecessor-version":[{"id":56863,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/56840\/revisions\/56863"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=56840"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=56840"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=56840"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}