Difference between git remote add and git clone

GitGit CloneGit Remote

Git Problem Overview


What does the clone command do? Is there any equivalent to it in svn?

What is the difference between

git remote add test git://github.com/user/test.git

And

git clone git://github.com/user/test.git

Does the name of the created repo matter?

Git Solutions


Solution 1 - Git

git remote add just creates an entry in your git config that specifies a name for a particular URL. You must have an existing git repo to use this.

git clone creates a new git repository by copying an existing one located at the URI you specify.

Solution 2 - Git

These are functionally similar (try it!):

git clone REMOTEURL foo

and:

mkdir foo

cd foo

git init

git remote add origin REMOTEURL

git pull origin master

cd ..

Now there are minor differences, but fundamentally you probably won't notice them. As an exercise left to the reader, compare the .git/config's from each directory.

Solution 3 - Git

The clone command creates a local copy of the repo you specified. remote add adds a remote repo that you can either push to or pull from.

The svn equivalent of clone is checkout.

Solution 4 - Git

git clone:

Will physically download the files into your computer. It will take space from your computer. If the repo is 200Mb, then it will download that all and place it in the directory you cloned.

git remote add:

Won't take space! It's more like a pointer! It doesn't increase your disk consumption. It just gets a snapshot of what branches are available and their git commit history I believe. It doesn't contain the actual file/folders of your project.

If you do:

git remote add TechLeadRepo  git://github.com/user/test.git

then you haven't added anything to your computer. After you've added it in your remote branches then you're able to get a list of all branches on that remote by doing:

git fetch --all

upon fetching (or pulling), you download the files And then if you wanted to do get your colleague's feature22 branch into your local, you'd just do

git checkout -b myLocalFeature22 TechLeadRepo/feature22

Had you cloned his repo then you would have to go into that local repository's directory and simply just checkout to your desired branch

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionnacho4dView Question on Stackoverflow
Solution 1 - GitJason LeBrunView Answer on Stackoverflow
Solution 2 - GitWes HardakerView Answer on Stackoverflow
Solution 3 - GitRafe KettlerView Answer on Stackoverflow
Solution 4 - GitmfaaniView Answer on Stackoverflow