Search code examples
gitgit-clonegit-fork

fork a Git repo locally (copy the Git repo?)


I am having a surprisingly difficult time finding an answer to this online.

I have a local Git repo on my filesystem. There is way too much history in there. I just need to clone it with depth=5 or so, etc.

I was thinking of copying the repo locally and then pruning it (getting rid of some old stuff).

Ideally I could copy the original repo with something like:

git clone --depth=5 /local/path/to/repo

but I can't find info on the exact command to run.

I tried that last command and I got this warning:

warning: --depth is ignored in local clones; use file:// instead


Solution

  • As the warning suggests:

    git clone --depth=5 file:///local/path/to/repo
    

    Here are the docs for this: https://mirrors.edge.kernel.org/pub/software/scm/git/docs/git-clone.html#URLS

    Thanks for edit, @Olegzandr