# git clone -b

2 messages from 2017-05-08 to 2017-05-08. Participants: Дилян Палаузов, Jeff King.
Thread: https://gitlist.dev/t/45899

## Дилян Палаузов, 2017-05-08 06:30

Subject: git clone -b
Message-ID: <219f3882-ec66-5c36-a157-5b920a2e4d04@aegee.org>
URL: https://gitlist.dev/e/219f3882-ec66-5c36-a157-5b920a2e4d04%40aegee.org

```
Hello,

why do these work:

git clone --bare -b 3.5 https://github.com/python/cpython A
git clone -b 3.6 A B
git clone -b 3.5 https://github.com/python/cpython C

but these not:

git clone -b 3.6 C D
git clone --no-local -b 3.6 C D

with git version 2.12.2.89.g49800c940?

Regards
   Дилян

```

## Jeff King, 2017-05-08 07:42

Subject: Re: git clone -b
Message-ID: <20170508074244.tcu2ywil2m47375k@sigill.intra.peff.net>
URL: https://gitlist.dev/e/20170508074244.tcu2ywil2m47375k%40sigill.intra.peff.net
In-Reply-To: <219f3882-ec66-5c36-a157-5b920a2e4d04@aegee.org>

```
On Mon, May 08, 2017 at 08:30:49AM +0200, Дилян Палаузов wrote:

> why do these work:
> 
> git clone --bare -b 3.5 https://github.com/python/cpython A
> git clone -b 3.6 A B

From the description of --bare in "git help clone":

  [...]the branch heads at the remote are copied directly to
  corresponding local branch heads, without mapping them to
  refs/remotes/origin/. When this option is used, neither
  remote-tracking branches nor the related configuration variables are
  created.

So because the upstream has a refs/heads/3.6 branch, so too does the
bare clone "A". And thus when you clone it asking for that branch, Git
can find it.

But in your non-bare example:

> git clone -b 3.5 https://github.com/python/cpython C
> 
> but these not:
> 
> git clone -b 3.6 C D
> git clone --no-local -b 3.6 C D

In the non-bare clone C, there is no local 3.6 branch. You only have the
remote-tracking branch refs/remotes/origin/3.6. So when you try to clone
from it, Git can't find the branch:

  $ git clone -b 3.6 C D
  Cloning into 'D'...
  fatal: Remote branch 3.6 not found in upstream origin
  fatal: The remote end hung up unexpectedly

It works if you create a local branch based on upstream's branch:

  $ git -C C checkout 3.6
  Branch 3.6 set up to track remote branch 3.6 from origin.
  Switched to a new branch '3.6'

  $ git clone -b 3.6 C D
  Cloning into 'D'...
  done.

-Peff

```
