Web Tutorials

Managing Multiple Remote Repositories

For one local repository, you can have several working remote repositories. The same is true for remote repositories. For one remote repository, you can have several local repositories. In this web tutorial, you will learn how to add and remove remote repositories to and from your local repository.

How to add a remote repository to a local repository?

Before adding a new remote repository, make sure that your “origin” remote repository is a public type repository. Otherwise, change the settings of your origin repository to public.

First, go to your origin repository and copy its url path.

Origin Repository URL path

Then go to the remote repository you wish to add to your local repository. Click the import repository button.

Fill in the blanks for importing your origin repository to your new remote repository.

After finishing the information, click the import repository button. This will then import the commit history, files, and settings of your origin repository to the new remote repository.

Next, copy the url path for the new remote repository and open a terminal/command prompt.

[OPTIONAL] In the command line, you are able to see the remote repositories already linked to your local repository via the git remote -v command.

As you can see, the meaning of origin can be found within this command. Origin basically represents the “original remote repository url” linked to your local repository. Thus the command git push origin master. This tells us that you want to push all the changed files found in your “local master branch” to your “origin” repository.

Now, to add the new remote repository, input into the command line:

git remote add repository_name repository_url

The repository_name represents the name of the remote repository you want to add to. For example:

git remote add Bitbucket https://parishilario@bitbucket.org/parishilario/test.git

In this example, I named the new remote repository “Bitbucket”. This is done in order to avoid confusion with the multiple remote repositories found within the local repository.

[OPTIONAL] You can see if the remote repository has successfully been added to your local repository via git remote -v.

Now you are able to commit to different remote repositories under the same local repository. The same Git commands apply for both remote repositories. However, when committing changes to remote repositories, you have to specify which remote repository you are committing to. Otherwise, the other remote repository will have no use. For example:

If you’re going to commit a new changed file to your remote repositories, you will have to do this individually.

In this image, I have only pushed my files to my origin repository. I would still have to push my files to the other remote repository.

Now I have successfully pushed the same file to both remote repositories.

[OPTIONAL] You can check where your remote repositories’ master branches are at via the git log command.

How to remove a remote repository from a local repository?

[OPTIONAL] Enter into the command line git remote -v to check what are the remote repositories listed under that specific local repository.

Here you are able to see the exact names for the remote repositories listed under your specific local repository.

Then enter into the command line:

git remote rm repository_name

To check if the command was successful, enter into the command line git remote -v one last time.

Congratulations! Now you are able to add and remove different remote repositories to a single local repository.

2 thoughts on “Managing Multiple Remote Repositories

  1. Clearly, you’ve used the entire quarantine days to learn a lot about ComSci. I’m really impressed and proud because you’ve made this site professionally. Support support support!

Leave a Reply

Your email address will not be published. Required fields are marked *