# strange "git clone" behavior wrt an active branch

4 messages from 2008-09-28 to 2008-09-28. Participants: Leo Razoumov, Santi Béjar.
Thread: https://gitlist.dev/t/15697

## Leo Razoumov, 2008-09-28 12:05

Subject: strange "git clone" behavior wrt an active branch
Message-ID: <ee2a733e0809280505n69f62e0fy89667c175bcc16c@mail.gmail.com>
URL: https://gitlist.dev/e/ee2a733e0809280505n69f62e0fy89667c175bcc16c%40mail.gmail.com

```
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, 2008-09-28 12:37

Subject: Re: strange "git clone" behavior wrt an active branch
Message-ID: <adf1fd3d0809280537k7adffe3dte9579fe70c7f990e@mail.gmail.com>
URL: https://gitlist.dev/e/adf1fd3d0809280537k7adffe3dte9579fe70c7f990e%40mail.gmail.com
In-Reply-To: <ee2a733e0809280505n69f62e0fy89667c175bcc16c@mail.gmail.com>

```
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:

$ 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, 2008-09-28 13:23

Subject: Re: strange "git clone" behavior wrt an active branch
Message-ID: <ee2a733e0809280623i30a9e298i30db2a84b8530d61@mail.gmail.com>
URL: https://gitlist.dev/e/ee2a733e0809280623i30a9e298i30db2a84b8530d61%40mail.gmail.com
In-Reply-To: <adf1fd3d0809280537k7adffe3dte9579fe70c7f990e@mail.gmail.com>

```
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 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, 2008-09-28 19:43

Subject: Re: strange "git clone" behavior wrt an active branch
Message-ID: <adf1fd3d0809281243x24974ddfk3fd6ce2667ac2edc@mail.gmail.com>
URL: https://gitlist.dev/e/adf1fd3d0809281243x24974ddfk3fd6ce2667ac2edc%40mail.gmail.com
In-Reply-To: <ee2a733e0809280623i30a9e298i30db2a84b8530d61@mail.gmail.com>

```
On Sun, Sep 28, 2008 at 3:23 PM, Leo Razoumov <slonik.az@gmail.com> wrote:
> 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--
>

```
