git remote add 和 git clone 的区别

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4855561/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 09:59:30  来源:igfitidea点击:

Difference between git remote add and git clone

gitgit-clonegit-remote

提问by nacho4d

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

什么是clone命令吗?在 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?

创建的 repo 的名称重要吗?

采纳答案by Jason LeBrun

git remote addjust 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 remote add只需在您的 git 配置中创建一个条目,指定特定 URL 的名称。你必须有一个现有的 git repo 才能使用它。

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

git clone通过复制位于您指定的 URI 处的现有存储库来创建一个新的 git 存储库。

回答by Wes Hardaker

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.

现在有一些细微的差异,但从根本上说,您可能不会注意到它们。作为留给读者的练习,比较每个目录中的 .git/config。

回答by Rafe Kettler

The clonecommand creates a local copy of the repo you specified. remote addadds a remote repo that you can either push to or pull from.

clone命令创建您指定的存储库的本地副本。remote add添加一个远程仓库,您可以推送或拉取。

The svn equivalent of cloneis checkout.

svn 的等价物clonecheckout

回答by Honey

git clone:

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.

将文件物理下载到您的计算机中。它将占用您计算机的空间。如果 repo 是 200Mb,那么它将下载所有内容并将其放在您克隆的目录中。

git remote add:

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.

不会占地方!它更像是一个指针!它不会增加您的磁盘消耗。它只是获取可用分支的快照以及我相信它们的 git 提交历史记录。它不包含项目的实际文件/文件夹。

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

在获取(或拉取)时,您下载文件然后如果您想将您同事的 feature22 分支放入您的本地,您只需这样做

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 checkoutto your desired branch

如果您克隆了他的 repo,那么您将不得不进入该本地存储库的目录,并且只需checkout转到您想要的分支