10

I'm getting the following error when issuing the command git clone --bare /path/to/repo:

fatal: attempt to fetch/clone from a shallow repository

First, what is a shallow repository and why doesn't it let me clone it?

Olivier Lalonde
  • 19,423
  • 28
  • 76
  • 91

2 Answers2

8

Rename .git/shallow to something else, clone, rename it back, copy .git/shallow to cloned repository

Chathuranga Chandrasekara
  • 20,548
  • 30
  • 97
  • 138
Harvie.CZ
  • 81
  • 1
  • 1
6

A shallow repository is a repository which does not contain the full history.

See the git-clone manpage:

--depth

Create a shallow clone with a history truncated to the specified number of revisions. A shallow repository has a number of limitations (you cannot clone or fetch from it, nor push from nor into it), but is adequate if you are only interested in the recent history of a large project with a long history, and would want to send in fixes as patches.

ThiefMaster
  • 310,957
  • 84
  • 592
  • 636
  • Thanks, but the problem is that I have "lost" the original repository. Is it possible to turn my shallow repo into a normal one? – Olivier Lalonde Jan 22 '11 at 21:03
  • 1
    Well, I deleted the .git/shallow file and it seems to be working. Hope it didn't break anything. – Olivier Lalonde Jan 22 '11 at 21:07
  • 1
    Create a new repository and import your codebase into it. If you only have a shallow repo you've already lost your history anyway so re-importing your code into a new repo won't make you lose anything. – ThiefMaster Jan 22 '11 at 21:07
  • You could also remove the `.git/shallow` file. I do not know if that has any negative side-effects though. – ThiefMaster Jan 22 '11 at 21:08
  • 1
    @Oliver: Examine the "root" commit of your repository; you should probably see that it thinks it has a parent, but that that parent commit doesn't actually exist in your repository. This could easily cause problems. For example, when I create a shallow clone and remove the .git/shallow file, git log runs into that oldest commit, can't find its parent, and dies: `fatal: Failed to traverse parents of commit ...`. – Cascabel Jan 23 '11 at 05:44