简体   繁体   English

git remote add 和 git clone 的区别

[英]Difference between git remote add and git clone

What does the clone command do? clone命令有什么作用? Is there any equivalent to it in svn?在 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 remote add just creates an entry in your git config that specifies a name for a particular URL. git remote add只是在您的 git 配置中创建一个条目,指定特定 URL 的名称。 You must have an existing git repo to use this.你必须有一个现有的 git repo 才能使用它。

git clone creates a new git repository by copying an existing one located at the URI you specify. git clone通过复制位于您指定的 URI 处的现有存储库来创建一个新的 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.作为留给读者的练习,比较每个目录中的 .git/config。

The clone command creates a local copy of the repo you specified. clone命令创建您指定的存储库的本地副本。 remote add adds a remote repo that you can either push to or pull from. remote add添加一个远程仓库,您可以推送或拉取。

The svn equivalent of clone is checkout . clone的 svn 等价物是checkout

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.它只是获取可用分支的快照以及我相信它们的 git 提交历史记录。 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在获取(或拉取)时,您下载文件然后如果您想将您同事的 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 checkout to your desired branch如果您克隆了他的 repo,那么您将不得不进入该本地存储库的目录,然后只需checkout到您想要的分支

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM