How to add a remote repository to your Git?

1 minute read

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.

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

  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.

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

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.

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 checking out the short tutorial!