threads / discuss / 15697

strange "git clone" behavior wrt an active branch

Subject: strange "git clone" behavior wrt an active branch

## tl;dr

4 messages between Sep 28, 2008 and Sep 28, 2008.

replies: 3people: 2as markdown or json

Leo Razoumov· Sep 28, 2008, 12:05 UTC · lore

Hi All, I am using the latest stable version git-1.6.0.2.

The man page for git-clone states explicitly that "git clone"
" Clones a repository into a newly created directory, ...[snip]...
  and creates and checks out an initial branch equal to the
  cloned repository's currently active branch. "

I noticed that while my active branch "My" happens to point to the same commit as the "master" the git clone will check out master instead of My (currently active branch). Is it a bug?

Here is the example that demontrates the problem
~> mkdir tmp
~/tmp> git init
~/tmp> cat > txt
some text
~/tmp> git add .
~/tmp> git ci -m 'init ci'
~/tmp> git branch -a
* master
~/tmp> git co -b My
~/tmp> git branch -a
* My
  master

Now "My" is my active branch in 'tmp' repo. It points to the same commit as the master. Now let us clone it

~/tmp> cd ..
~> git clone tmp tmp1
~> cd tmp1
~/tmp1> git branch -a
* master
  origin/HEAD
  origin/My
  origin/master

In the cloned repository 'tmp1', master branch is active. No local tracking branch for "My" was created. I think this behavior contradicts the man page. Is it a bug or feature??

Thanks, --Leo--

Santi Béjar· Sep 28, 2008, 12:37 UTC · re: Leo Razoumov · lore

Re: strange "git clone" behavior wrt an active branch

On Sun, Sep 28, 2008 at 2:05 PM, Leo Razoumov <slonik.az@gmail.com> wrote:
Show 13 quoted lines
> Hi All,
> I am using the latest stable version git-1.6.0.2.
>
> The man page for git-clone states explicitly that "git clone"
>
> " Clones a repository into a newly created directory, ...[snip]...
>  and creates and checks out an initial branch equal to the
>  cloned repository's currently active branch. "
>
> I noticed that while my active branch "My" happens to point to the
> same commit as the "master" the git clone will check out master
> instead of My (currently active branch). Is it a bug?
>

Currently it is only guessed which is the active branch (with a preference for the master branch as it is the default), as the current protocol does not allow tranfering the ref links:

$ git ls-remote $url $sha1 HEAD $sha1 $branchname ...

instead of: ref: refs/heads/master HEAD $sha1 $branchname ...

So, I think it is a current limitation that maybe should be documented.

HTH, Santi

Leo Razoumov· Sep 28, 2008, 13:23 UTC · re: Santi Béjar · lore

Re: strange "git clone" behavior wrt an active branch

On 9/28/08, Santi Béjar <santi@agolina.net> wrote:
Show 19 quoted lines
> On Sun, Sep 28, 2008 at 2:05 PM, Leo Razoumov <slonik.az@gmail.com> wrote:
>  > Hi All,
>  > I am using the latest stable version git-1.6.0.2.
>  >
>  > The man page for git-clone states explicitly that "git clone"
>  >
>  > " Clones a repository into a newly created directory, ...[snip]...
>  >  and creates and checks out an initial branch equal to the
>  >  cloned repository's currently active branch. "
>  >
>  > I noticed that while my active branch "My" happens to point to the
>  > same commit as the "master" the git clone will check out master
>  > instead of My (currently active branch). Is it a bug?
>  >
>
>
> Currently it is only guessed which is the active branch (with a
>  preference for the master branch as it is the default), as the current
>  protocol does not allow tranfering the ref links:

This is quite unfortunate design decision. There can be any number of local branches referring to the same commit. Without being able to pick into .git/HEAD it is impossible to decide which of them is "active".

--Leo--
Santi Béjar· Sep 28, 2008, 19:43 UTC · re: Leo Razoumov · lore

Re: strange "git clone" behavior wrt an active branch

On Sun, Sep 28, 2008 at 3:23 PM, Leo Razoumov <slonik.az@gmail.com> wrote:
Show 22 quoted lines
> On 9/28/08, Santi Béjar <santi@agolina.net> wrote:
>> On Sun, Sep 28, 2008 at 2:05 PM, Leo Razoumov <slonik.az@gmail.com> wrote:
>>  > Hi All,
>>  > I am using the latest stable version git-1.6.0.2.
>>  >
>>  > The man page for git-clone states explicitly that "git clone"
>>  >
>>  > " Clones a repository into a newly created directory, ...[snip]...
>>  >  and creates and checks out an initial branch equal to the
>>  >  cloned repository's currently active branch. "
>>  >
>>  > I noticed that while my active branch "My" happens to point to the
>>  > same commit as the "master" the git clone will check out master
>>  > instead of My (currently active branch). Is it a bug?
>>  >
>>
>>
>> Currently it is only guessed which is the active branch (with a
>>  preference for the master branch as it is the default), as the current
>>  protocol does not allow transferring the ref links:
>
> This is quite unfortunate design decision.

This is not a design decision, git has evolved, not designed. The ref links are younger than the transfer protocols.

> There can be any number of
> local branches referring to the same commit. Without being able to
> pick into .git/HEAD it is impossible to decide which of them is
> "active".
I'm sure patches are welcome.
>
> --Leo--
>

← back to recent threads