git – How to shallow clone a specific commit with depth 1?

Question:

Is it possible to shallow clone a specific commit in a repository, i.e. with depth 1? Something like

to get the repository state as it is at the commit with SHA 728a4d...?

The motivation is to avoid having to clone the whole repository, then check out that specific commit, when we’re only interested in the state of the repository at that specific commit.

Answer:

Starting with Git 2.5.0 (which needs to be available at both the client and server side) you can set uploadpack.allowReachableSHA1InWant=true on the server side to enable fetching of specific SHA1s:

Note that I did not find a syntax to do this with git clone directly.

Leave a Reply