path: root/Documentation
diff options
authorJonathan Tan <>2021-02-05 20:48:47 (GMT)
committerJunio C Hamano <>2021-02-05 21:49:53 (GMT)
commit59e1205d167c9acc17114a2f96425325470b1db8 (patch)
treea1f9580da38066b216c09ada5ef0cf9aa95e868b /Documentation
parentba2aa15129e59f248d8cdd30404bc78b5178f61d (diff)
ls-refs: report unborn targets of symrefs
When cloning, we choose the default branch based on the remote HEAD. But if there is no remote HEAD reported (which could happen if the target of the remote HEAD is unborn), we'll fall back to using our local init.defaultBranch. Traditionally this hasn't been a big deal, because most repos used "master" as the default. But these days it is likely to cause confusion if the server and client implementations choose different values (e.g., if the remote started with "main", we may choose "master" locally, create commits there, and then the user is surprised when they push to "master" and not "main"). To solve this, the remote needs to communicate the target of the HEAD symref, even if it is unborn, and "git clone" needs to use this information. Currently, symrefs that have unborn targets (such as in this case) are not communicated by the protocol. Teach Git to advertise and support the "unborn" feature in "ls-refs" (by default, this is advertised, but server administrators may turn this off through the lsrefs.unborn config). This feature indicates that "ls-refs" supports the "unborn" argument; when it is specified, "ls-refs" will send the HEAD symref with the name of its unborn target. This change is only for protocol v2. A similar change for protocol v0 would require independent protocol design (there being no analogous position to signal support for "unborn") and client-side plumbing of the data required, so the scope of this patch set is limited to protocol v2. The client side will be updated to use this in a subsequent commit. Signed-off-by: Jonathan Tan <> Signed-off-by: Junio C Hamano <>
Diffstat (limited to 'Documentation')
3 files changed, 21 insertions, 1 deletions
diff --git a/Documentation/config.txt b/Documentation/config.txt
index 6ba50b1..d08e83a 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -398,6 +398,8 @@ include::config/interactive.txt[]
diff --git a/Documentation/config/lsrefs.txt b/Documentation/config/lsrefs.txt
new file mode 100644
index 0000000..adeda0f
--- /dev/null
+++ b/Documentation/config/lsrefs.txt
@@ -0,0 +1,9 @@
+ May be "advertise" (the default), "allow", or "ignore". If "advertise",
+ the server will respond to the client sending "unborn" (as described in
+ protocol-v2.txt) and will advertise support for this feature during the
+ protocol v2 capability advertisement. "allow" is the same as
+ "advertise" except that the server will not advertise support for this
+ feature; this is useful for load-balanced servers that cannot be
+ updated atomically (for example), since the administrator could
+ configure "allow", then after a delay, configure "advertise".
diff --git a/Documentation/technical/protocol-v2.txt b/Documentation/technical/protocol-v2.txt
index 85daeb5..f772d90 100644
--- a/Documentation/technical/protocol-v2.txt
+++ b/Documentation/technical/protocol-v2.txt
@@ -192,11 +192,20 @@ ls-refs takes in the following arguments:
When specified, only references having a prefix matching one of
the provided prefixes are displayed.
+If the 'unborn' feature is advertised the following argument can be
+included in the client's request.
+ unborn
+ The server will send information about HEAD even if it is a symref
+ pointing to an unborn branch in the form "unborn HEAD
+ symref-target:<target>".
The output of ls-refs is as follows:
output = *ref
- ref = PKT-LINE(obj-id SP refname *(SP ref-attribute) LF)
+ obj-id-or-unborn = (obj-id | "unborn")
+ ref = PKT-LINE(obj-id-or-unborn SP refname *(SP ref-attribute) LF)
ref-attribute = (symref | peeled)
symref = "symref-target:" symref-target
peeled = "peeled:" obj-id