Difference between git remote add and git clone
-
27-10-2019 - |
Question
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?
Solution
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.
OTHER TIPS
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
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.
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
.
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
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
I believe after you do a checkout, then it would pull the latest changes and take space from your computer. Obviously it will only take the space for all the new commits you don't have.
Had you cloned his repo then you would have to go into that local repository's directory and checked out to your desired branch