Why can’t I push from a shallow clone?

As Junio C. Hamano (main Git maintainer) puts it:

Isn’t the rule more or less like:

If your shallow repository’s history does not extend long enough and the other repository forked before your truncated history, wyou cannot compute the common ancestor and you cannot push out.

Update 2014: see “Is git clone –depth 1 (shallow clone) more useful than it makes out?“: that limitation will be lifted with Git 1.9!

Update 2015: with Git 2.5+, you will even be able to fetch a single commit. See “Pull a specific commit from a remote git repository


Original answer (August 2011):

Actually, come to think of it, it is a lot stronger than “cannot compute
the common”.

The history may look like this:

          R---R---R
         /
  --R---R---X---X---S---S---S

where S are the commits you have in your shallow repository, and R are the commits that exist in the repository that receives your push.
Because your history is shallow, neither repository has ‘X‘ that are the commits that need to exist in order to keep the history of recipient repository complete; the recipient is not shallow to begin with, and we do not want to make it shallow.

If you cloned shallowly some time ago, worked without communicating with the other side while the other side progressed, AND if the other side’s progress included a rewind & rebuild of the history, you would see a similar topology.
The leftmost ‘S‘ in the above picture might have been the tip of the branch when you shallowly cloned with depth 1, and since then the remote end may have discarded topmost three commits and have rebuilt its history that leads to the rightmost ‘R‘.
In such a case pushing to the remote’s HEAD will fail.


So it could work in some case, but it is not supported:

If I have to say something on this…

  • I think “is not supported” is a succinct way to give good enough information, but it would only work for intelligent people.

  • Not everybody is intelligent; some try it out themselves, see that the operation seems to work for their limited number of trials, and would conclude it would work most of the time.
    And they congratulate their own intelligence for saying “most of the time”, not “always”.
    And they get upset when they see it does not work, even though they have been warned.


For more on the shallow clone update process, see “How to update a git shallow clone?“.

Leave a Comment