Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

git

I'm doing a git clone on a project following the instructions. But, do I need to do an init in the directory beforehand?

like image 710
airnet Avatar asked Mar 28 '14 23:03

airnet


People also ask

Does git clone include git init?

git clone is used to create a copy of an existing repository. Internally, git clone first calls git init to create a new repository. It then copies the data from the existing repository, and checks out a new set of working files.

When should I run git init?

git init is for every project Almost correct. git init is used to start using git on a project that's not under git. For projects that are already under git you use git clone .

How do I clone git for the first time?

From your repository page on GitHub, click the green button labeled Clone or download, and in the “Clone with HTTPs” section, copy the URL for your repository. Next, on your local machine, open your bash shell and change your current working directory to the location where you would like to clone your repository.


1 Answers

git clone is basically a combination of:

  • 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)

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

like image 145
michas Avatar answered Sep 19 '22 15:09

michas