git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: Udo <u.offermann@gmail.com>
Cc: Junio C Hamano <gitster@pobox.com>, git@vger.kernel.org
Subject: Re: git clone does not checkout active branch
Date: Wed, 3 Aug 2011 14:04:38 -0600	[thread overview]
Message-ID: <20110803200438.GC23848@sigill.intra.peff.net> (raw)
In-Reply-To: <loom.20110803T185528-8@post.gmane.org>

On Wed, Aug 03, 2011 at 04:56:43PM +0000, Udo wrote:

> I have a remote bare repository with two branches 'master' and 'testing', where
> HEAD refers to 'testing'. When cloning this repository git checks out 'master',
> if 'master' and 'testing' are on the same revision (i.e. HEAD == testing ==
> master). Only if 'testing' is one (or more) commit(s) behind or ahead, git clone
> checks out the 'testing' branch on the local side. I tried this with git 1.7.5
> on Mac OS X (10.6.8).

Yes, this is a known issue.

The git protocol just sends the list of refs and the objects they point
to. So the local clone is forced to guess which ref HEAD is pointing to.
E.g., with something like:

  28f599b... HEAD
  1234abc... refs/heads/master
  28f599b... refs/heads/testing

it can see that HEAD is probably "testing". But if it sees:

  28f599b... HEAD
  28f599b... refs/heads/master
  28f599b... refs/heads/testing

then it has to pick one arbitrarily. Our current heuristic is to prefer
"master" over others, and otherwise pick first alphabetically. So it's
at least deterministic, but as you noticed, it's not always right.

The real solution to this would be to extend the git protocol to convey
symbolic ref information (and then wait for both client and server to be
upgraded). Some patches have been floated in the past, but nothing came
of it[1]. Maybe it's time to resurrect them.

As a workaround, you can use "git clone -b testing ..." if you know
ahead of time that "testing" is what you want.

-Peff

[1] See:

    http://thread.gmane.org/gmane.comp.version-control.git/102039

and also:

    http://article.gmane.org/gmane.comp.version-control.git/113567

      reply	other threads:[~2011-08-03 20:04 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-03 16:56 git clone does not checkout active branch Udo
2011-08-03 20:04 ` Jeff King [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20110803200438.GC23848@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=u.offermann@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).