简体   繁体   English

Git克隆与添加远程? 使用哪个?

[英]Git clone versus add remote? Which to use?

In many cases I need to work with new sets of source code created by someone else. 在许多情况下,我需要使用其他人创建的新的源代码集。 They give me a URL to their repository like: 他们给我一个指向其存储库的URL,例如:

https://git.ourcompany.com/projects/SUPERNUKE/repos/supernuke/browse

To start work with this code, assuming that I have a c:/projects/SUPERNUKE directory on my machine I seem to have two basic options: (1) I can clone the repository, or (2) I can init my own repository and add the URL as a remote. 为了开始使用此代码,假设我的机器上有一个c:/projects/SUPERNUKE目录,我似乎有两个基本选项:(1)我可以克隆存储库,或者(2)我可以初始化自己的存储库,并且将网址添加为远程网址。 Which method should I prefer? 我应该选择哪种方法?

A secondary question is how to set up my local directory structure. 第二个问题是如何设置本地目录结构。 The project folder might have a lot of non code stuff in it, like data, design documents, scholarly papers and other things. 项目文件夹中可能包含许多非代码内容,例如数据,设计文档,学术论文等。 I am best off using a structure like the URL shown above, or is there a better way? 我最好使用上面显示的URL这样的结构,还是有更好的方法? In other words, to follow the structure from the URL above, what I would do (with Git Bash for Windows): 换句话说,要遵循上面URL的结构,我将要做什么(对于Windows的Git Bash):

cd c:/projects/SUPERNUKE
mkdir repos
cd repos
mkdir supernuke
cd supernuke
[then either clone or init]

If I follow this pattern, there are two things I still don't get. 如果遵循这种模式,我仍然有两件事没有得到。 Since I already am in the SUPERNUKE project directory, why am I adding it again below repos? 由于我已经在SUPERNUKE项目目录中,为什么还要在回购协议下再次添加它? Why not create directory "src" under repos and clone into that? 为什么不在存储库下创建目录“ src”并克隆到其中? In fact, why not just clone into the "repos" directory? 实际上,为什么不只是克隆到“ repos”目录中呢? Can I not clone multiple repos in the same directory? 我不能在同一目录中克隆多个存储库吗? Why would the creator have a "browse" directory? 创建者为什么会有一个“浏览”目录?

You should use clone as that is what it is for. 您应该使用clone因为这就是它的用途。 It creates the directory, inits it as Git repo, sets the remote and fetches the changes. 它创建目录,将其作为Git存储库初始化,设置远程目录并获取更改。

Adding a remote is more helpful if you have a clone and want to add a further remote that points to another remote repository in the same network of clones, eg the one of your co-worker if you want to get commits from him that are not yet on the central Git repository. 如果您有一个克隆并想要添加另一个指向同一克隆网络中另一个远程存储库的远程,则添加一个远程服务器会更有用,例如,如果您想从他的同事那里获得不属于他的提交,则请与您的同事一起仍在中央Git存储库中。

How you layout your local directories is totally up to you. 布局本地目录的方式完全取决于您。 In the URL it is simply the path /projects/SUPERNUKE/repos/ where all repositories are stored and then there is a repository browse that belongs to the user or group supernuke on the GitLab server or whatever hosting software you use. 在URL中,仅存储所有存储库的路径/projects/SUPERNUKE/repos/ ,然后存在一个存储库browse ,该browse属于GitLab服务器或您使用的任何托管软件上的用户或组supernuke

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

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