Search code examples
gitgit-remote

Should git repository remotes on the local filesystem be prefixed with file://?


If I want to define a remote for a git repository that is on the same filesystem, it was suggested to me that it ought to be prefixed with file://. That is,

git remote add theremote file:///path/to/repo

I'd like to know if there are any problems with just using

git remote add theremote /path/to/repo

I did a quick check and git remote add, git clone, git pull, and git push all seem happy with the simpler option.

Are there any cases where the lack of a file:// prefix will cause an issue?


Solution

  • Git handles local paths just fine. There's no need to use file://, although there is a subtle difference (quoted from the documentation):

    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 much less efficient. 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 VCS or something similar (see Git Internals for maintenance tasks).