Skip to content

Write Git config core.alternateRefsPrefixes setting

In gitlab-com/gl-infra/production#912 (closed), we saw that pushes got really slow (3-4 minutes) when alternates were enabled for the CE and EE repositories. This happened because the repositories were advertising thousands of .have references (https://github.com/git/git/blob/a6a95cd1b46e48e5fe06bdbb0839a67ebeef4682/builtin/receive-pack.c#L268-L276).

Why was it doing that? From https://github.com/git/git/commit/465e73fff380808f0ba3fb17984ab8636afb6405:

When pushing into a repository that borrows its objects from an alternate object store, "git receive-pack" that responds to the push request on the other side lists the tips of refs in the alternate to reduce the amount of objects transferred. This sometimes is detrimental when the number of refs in the alternate is absurdly large, in which case the bandwidth saved in potentially fewer objects transferred is wasted in excessively large ref advertisement. The alternate refs that are advertised are now configurable with a pair of configuration variables.

I did a quick test and added the alternateRefsPrefixes = "refs/heads/private" config to the file, so now we have:

[core]
	bare = true
	repositoryformatversion = 0
	filemode = true
	sparseCheckout = true
	commitGraph = true
	splitIndex = true
	alternateRefsPrefixes = "refs/heads/private"

Note refs/heads/private is arbitrary; perhaps we should just set this to refs/alternates/public for now?

Should this just be a global setting in Omnibus? I don't think we need to configure this on a per repo basis.

Edited by Stan Hu
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information