Michael Lihs Michael Lihs - 3 months ago 11
Bash Question

`git clone /DIRECTORY` versus `git clone file:///DIRECTORY`

I have a problem with a

git clone
command. When I run



$ git clone /SOURCE_DIRECTORY /TARGET_DIRECTORY


Everything works fine and I get

Initialized empty Git repository in /TARGET_DIRECTORY/.git/


When I run this command (only
file://
added)

$ git clone file:///SOURCE_DIRECTORY /TARGET_DIRECTORY


I get

Initialized empty Git repository in /TARGET_DIRECTORY/.git/
remote: Counting objects: 737, done.
remote: Compressing objects: 100% (189/189), done.
remote: Total 737 (delta 264), reused 725 (delta 256)
Receiving objects: 100% (737/737), 68.25 KiB, done.
Resolving deltas: 100% (264/264), done.
error: Trying to write ref HEAD with nonexistant object XXXXXXXX
fatal: Cannot update the ref 'HEAD'.


Can anybody tell me, what's the difference between
/DIRECTORY
and
file:///DIRECTORY
and why I get a different result here?

Answer

From the link to the Git Docs that @ElpieKay commented with:

Git operates slightly differently if you explicitly specify file:// at the beginning of the URL. If you just specify the path, Git tries to use hardlinks or directly copy the files it needs. If you specify file://, Git fires up the processes that it normally uses to transfer data over a network which is generally a lot less efficient method of transferring the data. The main reason to specify the file:// prefix is if you want a clean copy of the repository with extraneous references or objects left out – generally after an import from another version-control system or something similar

So the extra output that you see signifies the fact that Git is spinning up its network stack to transfer the data, instead of doing a local copy, as it does in your first example. Thus, unless you have a reason to use the network stack to transfer the data, it's better to drop the file://.

As for the error:

error: Trying to write ref HEAD with nonexistant object XXXXXXXX
fatal: Cannot update the ref 'HEAD'.

These answers indicate that this can be caused by using an older version of Git:

So try upgrading your Git client.