nacho4d
nacho4d

Reputation: 45088

Difference between git remote add and git clone

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?

Upvotes: 82

Views: 70631

Answers (5)

Wes Hardaker
Wes Hardaker

Reputation: 22252

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 main
 # 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.

Upvotes: 63

Omkar Kulkarni
Omkar Kulkarni

Reputation: 167

git clone URL -

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

git remote add origin -

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 files/folders of your project.

Upvotes: 0

mfaani
mfaani

Reputation: 36277

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

Upvotes: 12

Jason LeBrun
Jason LeBrun

Reputation: 13293

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.

Upvotes: 70

Rafe Kettler
Rafe Kettler

Reputation: 76955

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.

Upvotes: 11

Related Questions