在对项目执行 'git clone' 之前,我是否需要执行 'git init'

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22724921/
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 17:56:38  来源:igfitidea点击:

Do I need to do 'git init' before doing 'git clone' on a project

git

提问by airnet

I'm doing a git cloneon a project following the instructions. But, do I need to do an initin the directory beforehand?

我正在git clone按照说明做一个项目。但是,我需要init事先在目录中做一个吗?

回答by michas

git cloneis basically a combination of:

git clone基本上是以下组合:

  • git init(create the local repository)
  • git remote add(add the URL to that repository)
  • git fetch(fetch all branches from that URL to your local repository)
  • git checkout(create all the files of the main branch in your working tree)
  • git init(创建本地存储库)
  • git remote add(将 URL 添加到该存储库)
  • git fetch(从该 URL 获取所有分支到您的本地存储库)
  • git checkout(在您的工作树中创建主分支的所有文件)

Therefore, no, you don't have to do a git init, because it is already done by git clone.

因此,不,您不必执行 a git init,因为它已经由 完成了git clone

回答by jornane

git initwill create a new repository. When running git clone, what actually happens in the background is a git init, followed by git remote add origin ${URL}and then a git pull.

git init将创建一个新的存储库。运行时git clone,后台实际发生的是 a git init,然后是git remote add origin ${URL}a git pull

Typically, you only use git initif you already have code and you want to put it in a new Git repository.

通常,仅git init当您已经拥有代码并且想要将其放入新的 Git 存储库时才使用。

In answer to your question: if you want to clone a project, then you do not need git init.

回答你的问题:如果你想克隆一个项目,那么你不需要git init.