25

We have a remote repository on a shared folder in our local network. I attempted to make a shallow clone:

git clone --depth 1 //gitrepos-pc/git/foo/

It gave me this warning, and made a full clone:

warning: --depth is ignored in local clones; use file:// instead.
sashoalm
  • 75,001
  • 122
  • 434
  • 781

1 Answers1

20

Ok, after some experimenting I got it, I had to use

git clone --depth 1 file:////gitrepos-pc/git/foo/

It had to be 4 slashes, not 3.

sashoalm
  • 75,001
  • 122
  • 434
  • 781
  • 3
    `file://` is the protocol. `//` signifies a Samba share (from the Windows `\\`). Put those two together, and you've got `file:////`. It would be simpler if git understood the `smb://` protocol (it does, kind of, through `file://`, but I don't know it does this). – rubenvb Nov 02 '16 at 15:05
  • 1
    @rubenvb That explains it, thanks. So the usual 3 slashes is really `file://` + the starting slash of an ordinary local path I guess. – sashoalm Nov 02 '16 at 15:06
  • That's my guess to it yes `:)`. – rubenvb Nov 02 '16 at 15:08
  • 2
    How to use it with relative paths: https://stackoverflow.com/questions/47307578/how-to-shallow-clone-a-local-directory-in-git-with-a-relative-path – Ciro Santilli OurBigBook.com Nov 15 '17 at 12:34
  • Note that when you specify a TARGET path to clone into (i.e. for outside of the current directory), you just use a standard local path for that argument. – BuvinJ Jan 22 '18 at 20:17
  • In my case I had to use `file:///` instead to make it work. – Cedric Zoppolo Oct 28 '19 at 19:35
  • I found I couldn't use relative paths with `file://`, so I used `$(pwd)` to save myself a lot of typing: `git clone --depth 1 file://$(pwd)/src_repo new_repo` – Dale C. Anderson Aug 25 '22 at 00:48