When another developer tries to fetch it, nothing happens. (An anonymous branch won't be fetched!?)
Anonymous branches are problematic. Parts of Git believe they are branches, and parts do not. If they do exist, then every commit is its own anonymous branch.1 It's probably better, for most purposes, to just think of selecting a commit with or without also selecting some or all of its ancestors. Selecting commit bacacab
without ancestry gets you the one commit, and selecting it with ancestry makes it act like an anonymous branch.
In any case, what git fetch
always copies unchanged—because it must—is composed of the commit objects themselves and the things those refer to: any trees or blobs required, and any earlier commits required.2 For annotated tag objects, Git copies the tag object itself unchanged, and adds the tag's target-object to the set of objects required (to be copied if not already present). How it finds those object IDs is by the names—any reference names, not just branch or tag names—presented by the other Git, the one your Git is fetching from. So this means that there must be a name. But that's a name in the other Git, in the other repository; the name, if any, to use in your repository is something under your control.
As it turns out, there is a bug of sorts where, if Git is fetching just a tag name, and is not instructed to copy the tag name explicitly, it fails to write anything at all (except for the FETCH_HEAD
file) in some cases. See my answer to Why is git fetch not fetching any tags? In short, though, if you git fetch --tags
, you will get their—the other Git's—tag name copied to a tag of the same name in your own repository, and you can then use that tag name to look up the commit (and its ancestors).
1For that matter, a single commit could be the tip commit of an infinite number of anonymous branches. Who is to say if the lack of a name is the same name as a second lack of a name? Clearly the anonymous branch ending at commit dadf00d
is different from the anonymous branch ending at bl00de1f
, so no-name definitely doesn't match no-name. So why does, or doesn't, no-name for ac0ffee
match no-name for ac0ffee
? (This is a rhetorical / philosophical question, meant to make one think about the nature of commits and branch names in Git, rather than to get a concrete answer—though I do have my own concrete answer. :-) )
2This does get modified for shallow clones. Here, commits are copied up to some "depth" value, and then Git inserts a shallow graft, artificially pretending that the commit has no parents (by writing the commit ID to .git/shallow
). But the commit is actually copied intact; it's just the graph-walk that gets truncated.