# shallow&single-branch clone?

2 messages from 2011-10-19 to 2011-10-21. Participants: Norbert Nemec, Jeff King.
Thread: https://gitlist.dev/t/28716

## Norbert Nemec, 2011-10-19 13:30

Subject: shallow&single-branch clone?
Message-ID: <4E9ED108.5020505@native-instruments.de>
URL: https://gitlist.dev/e/4E9ED108.5020505%40native-instruments.de

```
Hi there,

it seems like there is no way to clone a single branch with truncated 
history.

Truncating history is done by 'git clone --depth 1', there is not way to 
restrict 'clone' to a single branch (the --branch option still downloads 
all branches and only then chooses something other than HEAD as active 
branch).

The manual sequence
	git init
	git remote add -t master -f origin URL
	git checkout
allows a clone of a single branch but offers no means to truncate history.

The least intrusive solution would be an additional option to clone, 
perhaps '--branch-only'.

More user friendly, this options should be on by default when --depth is 
set. After all: who would expect branches to be cloned when the history 
is explicitely truncated?

Ideas?

Greetings,
Norbert Nemec

```

## Jeff King, 2011-10-21 01:22

Subject: Re: shallow&single-branch clone?
Message-ID: <20111021012259.GA13421@sigill.intra.peff.net>
URL: https://gitlist.dev/e/20111021012259.GA13421%40sigill.intra.peff.net
In-Reply-To: <4E9ED108.5020505@native-instruments.de>

```
On Wed, Oct 19, 2011 at 03:30:48PM +0200, Norbert Nemec wrote:

> Truncating history is done by 'git clone --depth 1', there is not way
> to restrict 'clone' to a single branch (the --branch option still
> downloads all branches and only then chooses something other than
> HEAD as active branch).
> 
> The manual sequence
> 	git init
> 	git remote add -t master -f origin URL
> 	git checkout
> allows a clone of a single branch but offers no means to truncate history.

You can do:

  git init
  git remote add -t master origin URL
  git fetch --depth=1
  git checkout

But obviously that's not as nice as an option to clone.

> The least intrusive solution would be an additional option to clone,
> perhaps '--branch-only'.

Agreed, that would be better. We might want to make it more flexible,
like:

  git clone --fetch=branch1 --fetch=branch2

and then by default choose "-b branch1" since it was mentioned first.

> More user friendly, this options should be on by default when --depth
> is set. After all: who would expect branches to be cloned when the
> history is explicitely truncated?

Yeah, that probably makes sense. If the branches are related, it's
probably not saving much, but if you have unrelated branches, it would
be a nice convenience. OTOH, how would you tell git "no, I really do
want the tip of every branch"?

-Peff

```
