Reputation: 2673
I'm doing a git clone
on a project following the instructions. But, do I need to do an init
in the directory beforehand?
Upvotes: 88
Views: 64455
Reputation: 1515
git init
will create a new repository. When running git clone
, what actually happens in the background is:
git init
git remote add origin ${URL}
git pull
So it's a nice shorthand. Typically, you only use git init
if you already have code and you want to put it in a new Git repository.
In answer to your question: if you want to clone a project, then you do not need git init
.
Upvotes: 17
Reputation: 26555
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
.
Upvotes: 175