How to add a remote repository to your Git?

When you work in a company with lots of employees or you collaborate on a project with many participants, who contribute to the same code base, it’s definitely is a good idea to use git.

Myself I have never experienced any problems until I’ve got a project with many contributors and their codes that I’d wish to see. And/or to cherry-pick some commits later on. Anyhow it led me to the point that it became a nightmare. So I struggled a little bit until I realized that it cannot be made so dumb – There must be a proper way to manage this, I thought.

Screen Shot 2017-04-11 at 12.36.48

And frankly, git has indeed made it fairly easy by introducing git remote add command for us.

As it follows here in the example, I am going to add another repository by executing

git remote add codebuddies [email protected]:codebuddiesdotorg/codebuddies.git

Where codebuddies is a resource name and [email protected]:codebuddiesdotorg/codebuddies.git is a resource URL which was origin by the way, but I changed it using git remote set-url once I forked codebuddies repository.

Regardless, using git fetch, I received all the repositories available.

Screen Shot 2017-04-11 at 13.01.44.png

And now I can take a look at other branches prepared there by typing:

git checkout codebuddies/master

Don’t worry it won’t do any harm, though. You are going to be in so-called detached HEAD which is totally fine in case you want to observe the changes and to play around in your work ground, for instance, to run meteor server.

Screen Shot 2017-04-11 at 13.19.51

Although, if you want to save your changes that you’ve done here you have to create a new branch with git checkout -b or git checkout b <remote/branch-name> before entering the ‘detached HEAD’ state.

No matter which way you decide to go, you can run a cherry-pick with commit id available in the other remote branch. So good luck!

Thanks a lot for bypassing this short tutorial. As always don’t forget to leave comments below if you have any questions, press thumb up, and I highly appreciate for sharing the link with others!

Published by

Aidan Rudkovskyi

Software Engineer

2 thoughts on “How to add a remote repository to your Git?”

Leave a Reply