3

I am trying to build a workflow which syncs to a remote git repo, with as little overhead as possible. Some of the repos I want to sync are quite large and I don't need the history (--depth 1). The real issue is that I want to sync to any of: a branch, a tag, a SHA.

I can't clone at a SHA, as far as I can tell.

Then I read this wonderful comment: Retrieve specific commit from a remote Git repository

It suggests that git fetch <remote> <sha> works. Empirically it works on file:// repos and on GitHub repos. My question is really: can I rely on this? Or are there reasons that major providers might disable this?

Tim Hockin
  • 3,567
  • 13
  • 18
  • So the question is what some corporate entity _will_ do? That’s a programming issue? You need CrystalBall.org. – matt Jul 03 '20 at 01:40
  • More like "what is the general experience people have had around this". If someone knows of a major reason not to make this assumption, I'd love to know. – Tim Hockin Jul 03 '20 at 01:48
  • I’m sure you would, but I’m still not persuaded it’s on topic for a programming site. Collecting anecdotes is not what we do. – matt Jul 03 '20 at 01:51

1 Answers1

2

You can rely on this if the provider uses the default Git implementation (that is, the canonical one written in C) and they support protocol v2 (protocol.version=2) because the default implementation doesn't do any checks in that case. GitHub offers that, and some other providers do as well.

However, other providers may use a different implementation (e.g., Google and Gerrit use JGit, I believe) and not all providers support protocol version 2, so it isn't guaranteed that all providers will support it.

The usual case for not supporting it is that the provider doesn't want people pulling objects that are no longer referenced. Some providers also share objects between forks and don't want objects available from one fork accessible from another. Fetching arbitrary commits would let folks access data that was no longer accessible or that was from a private fork.

bk2204
  • 64,793
  • 6
  • 84
  • 100