Sato Sato - 23 days ago 11
Git Question

Is it saft to git clone to the same git directory

for example, first there is no

test
directory, i
git clone
:

`git clone git@github.com:test/test.git test`


then after some push/pull, I do it again:

`git clone git@github.com:test/test.git test`


will the second clone damage the local test repo?

REASON:

because i do
clone
in a one-time script, this script is supposed to run one time, ideally, but if it fails, or on other reason, it might be ran multiple times, so
clone
will be ran multiple times too. if its not ok, i will do a
rm -rf test
first.

Answer Source

As we can read in the git docs:

Clones a repository into a newly created directory

and

Cloning into an existing directory is only allowed if the directory is empty

In your case, cloning into an already cloned directory just won't work.

In your script you can handle/test the return code of git command and perform proper actions if git clone fails or not.

Replying to your question: yes, it's safe to run git clone multiple time. The repository won't be damaged.