threads / discuss / 45899

git clone -b

Subject: git clone -b

## tl;dr

2 messages between May 8, 2017 and May 8, 2017.

replies: 1people: 2as markdown or json

Дилян Палаузов· May 8, 2017, 06:30 UTC · lore
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· May 8, 2017, 07:42 UTC · re: Дилян Палаузов · lore

Re: git clone -b

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:
Show 6 quoted lines
> 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

← back to recent threads