How to merge a Git repository with another remote one

Recently I migrated a Git repository from Github to Bitbucket.

Then I need to merge some new code in the old repository to the new one. Want to learn how to merge a Git repository with another remote one? Keep reading!

In your machine

Let's say your code is already pointed to the new repository (Bitbucket), so need to add the old one:

git remote add github git@github.com:user/repo.git

Note to change the user and repo values with yours.

This will add the repository with the name github for this example.

Merge in your current local branch

In order to merge a remote branch to your current local branch, just run:

git pull github master

This will merge your current local branch with the remote master branch at Github repository.

How to remove the link to the old repository

When you're done and want to remove the link to the old repository at Github, just run:

git remote remove github

That's all! Leave a comment with your doubts or experiencies 👍

David Burgos

Read more posts by this author.