Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between adding and cloning a remote repository?

Tags:

git

What's the difference between adding a remote repository and cloning a remote repository? I'm reading the pragmatic guide to git and they are talking about distributed environments and using git remote add. I'm finding the section difficult to understand, and why I should use it over clone.

Many thanks

like image 927
screenm0nkey Avatar asked Sep 12 '25 18:09

screenm0nkey


2 Answers

Using git remote add is connecting another (remote) repository to the current repository so you can pull and push with the remote repository. For example, I do this when I push things to Github, because I already have my own "master" repository as origin.

Using git clone creates a new repository on your local system that is set up to connect to a remote repository. I would do this when getting a clone of another published project from somewhere, or making another copy of one of my own projects (perhaps on a different computer).

like image 106
Greg Hewgill Avatar answered Sep 15 '25 09:09

Greg Hewgill


Git clone sets up a new repository similar to the one you are cloning ( hence the name clone!) and "adds" the remote repository from which you cloned as the remote with the name origin

Just doing the last part of setting up a remote is "adding a remote repository" and doing the whole thing and getting a new clone is cloning. Note that when you add a remote repository, you already have a repository. When you clone, you do not already have the repository.

A repository can have muliple remotes added to it via git remote add. Usually these are remote repositories of the same repo's clones on peers and servers with which you push and pull.

like image 22
manojlds Avatar answered Sep 15 '25 11:09

manojlds